tags:

views:

115

answers:

5
+1  Q: 

What is =& in PHP

look at this example and there is a line

  $client =& new xmlrpc_client('/xml-rpc', 'api.quicktate.com', 80);
  $client->return_type = 'xmlrpcvals';

what is the =& and what is the -> in $client->return_type mean

A: 

This is called returning by reference.

treeface
...and this is not longer necessary in PHP5 where objects are always passed by reference.
Adam Byrtek
+4  A: 

The = and the & should* have a space between them - they're two different operators. The & means get a reference to this.

The -> is for object member access - this means assign 'xmlrpcvals' to the return_type member of $client.

* see comments for clarification

Skilldrick
treeface
Skilldrick
BoltClock
+2  A: 

The =& assigns the variable a reference to the object rather than copying it. It is two separate operators (assignment and getting a reference) but they are often written together.

The -> is a member access operator; in the example it means to get the return_type that belongs to the XML-RPC client.

kindall
+2  A: 

Is to pass a variable by reference

<?php  
   $a = 5; 
   $b =& $a; 
   $b = 6; 

   echo "a: "; 
   var_dump($a); 
   echo "b: "; 
   var_dump($b); 
?>

output:

a: int(6)
b: int(6) 
el_quick
+2  A: 

Starting with the last question first;

what is the -> in $client->return_type mean?

-> is the operator you use to access properties and methods of an object in PHP. Most languages, such as Java or Javascript use the dot operator for the same thing. It (probably) derives from the C syntax for accessing members of a struct.

Then that first question...

what is the =& ?

The short version is, in your example, it's a relic you no longer need; a hangover from PHP4 which you no longer need if you use PHP5. But note this is specific to your example.

For the long version, so you really understand what's going on read http://derickrethans.nl/talks/phparch-php-variables-article.pdf about References in PHP

HarryF