Jump to content

Didn't understand this bit from the manual..


Slips

Recommended Posts

Hello all,

 

My knowledge in PHP is growing everyday as I try out more stuff but I really didn't understand this bit :

"Note: Please note that the ternary operator is a statement, and that it doesn't evaluate to a variable, but to the result of a statement. This is important to know if you want to return a variable by reference. The statement return $var == 42 ? $a : $b; in a return-by-reference function will therefore not work and a warning is issued in later PHP versions. ".

 

taken from the page : http://www.php.net/manual/en/language.operators.comparison.php

 

From what I understood, if I was to use a ternery condition in the return statement, and return a referenced variable as a result, it

shouldn't work?

 

So this shouldn't work?

$int = 10;

function testReturn(&$referencedVariable) {
return (1==1) ? $referencedVariable : FALSE;
}

echo testReturn($int);

 

But it does. Anyways i'm pretty sure I didn't understand this right, so help with this is really appreciated :D

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.