2

Possible Duplicate:
Reference - What does this symbol mean in PHP?

I've been programming PHP for over 5 years and I've just came across something I have never seen whilst creating a wordpress theme.

$images =& get_children( 'post_type=attachment&post_mime_type=image' );

What does $images =& do? It's the =& I'm concerned about. I have a feeling it's bitwise but I wouldn't understand what it's doing even if it was.

Any help?

Community
  • 1
  • 1
Jamie Redmond
  • 731
  • 2
  • 12
  • 14
  • 1
    A bad way to write code. It's actually `= &get_children` (note the space between the two tokens). Given your experience, the `&` you should know. – Linus Kleen Feb 11 '11 at 20:08
  • 1
    [Reference - What does this symbol mean in PHP?](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – BoltClock Feb 11 '11 at 20:09
  • the bitwise assigment is &= and do a bitwise and beetween the left and rigth part of expression putting the result into the left one – Eineki Feb 11 '11 at 20:10
  • 4
    @Eineki Delete that quick. Before someone notices. – Linus Kleen Feb 11 '11 at 20:11
  • See also [Returning references](http://php.net/manual/en/language.references.return.php). – netcoder Feb 11 '11 at 20:14
  • @Linus Kleen Now I feel stupid! Just goes to show what happens when people go against convention. – Jamie Redmond Feb 11 '11 at 20:20
  • @Jamie Nah. No need to degrade yourself. There's actually no convention that prohibits you to write that. The parser just goes ahead and says: *Oh neat. Yet another whitespace I don't have to ignore. Cause it's not there! Whooo!* – Linus Kleen Feb 11 '11 at 20:51
  • @Linus Kleen Why? Is not &= the bitwise assigment as stated in http://www.php.net/manual/en/language.operators.precedence.php ? – Eineki Feb 12 '11 at 06:57
  • @Eineki 1 + 1 = 2. This is also a true statement. Yet, it, too, has nothing to do with the question. The question is about `=&` not `&=`. – Linus Kleen Feb 12 '11 at 09:22

3 Answers3

4

Assigns a value by reference

http://www.php.net/manual/en/language.operators.assignment.php

Assignment by reference means that both variables end up pointing at the same data, and nothing is copied anywhere.

Alfabravo
  • 7,493
  • 6
  • 46
  • 82
3

=& is the assignment by reference operator.

You can find out more about references here: http://php.net/manual/en/language.references.php

Crozin
  • 43,890
  • 13
  • 88
  • 135
1

It's an assign by reference.

http://php.net/manual/en/language.references.pass.php

As opposed to a normal pass by value assignment.

the JinX
  • 1,950
  • 1
  • 18
  • 23