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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.