return reference from method 
Author Message
 return reference from method

Hi!

What is the correct syntax to return a reference from a method in php?

$ref = &$object->method();
does not work (parse error)

$ref = $object->&method();
gives also a parse error.

is the only way to use a referenced in/ouput paramter?
like
$object->method(&$ref);

--
mac

real email-adress: mac clondiag com



Mon, 30 May 2005 21:23:26 GMT  
 return reference from method
Hi Micheal,

Quote:
> What is the correct syntax to return a reference from a method in php?

You can't make a reference of a Class-Method you can use
a Reference of the Instance

Quote:
> $ref = $object->&method();
> gives also a parse error.

Why not using $object itself ?

Kind Regards.
Karl Heinz
--
Dipl.Ing.(FH) Karl Heinz Marbaise | Minkenberg Medien GmbH
Software Entwicker                | www.minkenberg-medien.de
Tel.: +49 (2452) 98 91 40         | Roermonderstr. 128a
Fax.: +49 (2452) 98 91 42         | D-52525 Heinsberg



Mon, 30 May 2005 21:45:33 GMT  
 return reference from method

Quote:

> Hi Micheal,

>>What is the correct syntax to return a reference from a method in php?

> You can't make a reference of a Class-Method you can use
> a Reference of the Instance

I want to return a reference to a class variable from a method, not a
reference to a method.

Quote:

>>$ref = $object->&method();
>>gives also a parse error.

> Why not using $object itself ?

because i do not need a reference to $object but a reference to an
instance varible inside $object. (i can't access it directy, i have to
use the method).

--
bye, mac

real email-adress: mac clondiag com



Mon, 30 May 2005 22:13:20 GMT  
 return reference from method

Quote:

> What is the correct syntax to return a reference from a method in php?

> $ref = &$object->method();
> does not work (parse error)

> $ref = $object->&method();
> gives also a parse error.

> is the only way to use a referenced in/ouput paramter?
> like
> $object->method(&$ref);

function & foo() {
   return $this;

Quote:
}

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.


Mon, 30 May 2005 22:35:26 GMT  
 return reference from method
The question has been answered so I won't repeat the answer, except to note
the following "gotcha."

When you return references, be certain that the object or variable you are
referencing will still exist when the function returns!  As with any
language, if the object has been garbage-collected then the reference will
no longer be valid.  An interpreter, like PHP, /should/ be able to handle
such a thing gracefully (although of course it might "leak" memory in so
doing), but it's a source of subtle bugs that needs to be watched-for at
coding-time.

Quote:

> What is the correct syntax to return a reference from a method in php?

> $ref = &$object->method();
> does not work (parse error)

> $ref = $object->&method();
> gives also a parse error.

> is the only way to use a referenced in/ouput paramter?
> like
> $object->method(&$ref);



Mon, 30 May 2005 23:41:09 GMT  
 return reference from method

Quote:

> When you return references, be certain that the object or variable you are
> referencing will still exist when the function returns!  As with any
> language, if the object has been garbage-collected then the reference will
> no longer be valid.  An interpreter, like PHP, /should/ be able to handle
> such a thing gracefully (although of course it might "leak" memory in so
> doing), but it's a source of subtle bugs that needs to be watched-for at
> coding-time.

To add to that: i've had major problems with objects disappearing even
though i still have open references to them. It even happens that the
object disappears between one line and the next, such that i get a null
pointer exception on line 17 when the same object was used without problem
on line 16.

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.



Mon, 30 May 2005 23:50:10 GMT  
 return reference from method

Quote:

> Hi!

> What is the correct syntax to return a reference from a method in php?

> $ref = &$object->method();
> does not work (parse error)

that's wrong it works.

--
mac

real email-adress: mac clondiag com



Tue, 31 May 2005 20:17:43 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. ActiveX Double return value passed by reference?

2. Method that returns true if two strings are scrambled versions of eachother

3. method returning array

4. Object returned by methods on Collection

5. String Collection returned from OCX method

6. Troubles returning Reference Variables

7. Troubles returning Reference Variables

8. OCX Method That Returns a Value

9. The return method of the LIST class in the ISE 2.3 libraries

10. Implementing virtual functions that return reference to self

11. Vi that returns the reference of a specific control

12. I Have been unable to get return data from Winsock.GetData method in LabView, Any Ideas

 

 
Powered by phpBB® Forum Software