Page 1 of 1

who can tell me what it's meaning of the following code?

Posted: Thu Apr 09, 2009 8:18 am
by addaddc
<?php $act && $act = 'view'; ?>


$act is a string.

Thank you.

Re: who can tell me what it's meaning of the following code?

Posted: Thu Apr 09, 2009 8:54 am
by jayshields
Without testing I assume all it does is assign 'view' to $act.

Re: who can tell me what it's meaning of the following code?

Posted: Thu Apr 09, 2009 10:31 am
by Mark Baker
addaddc wrote:<?php $act && $act = 'view'; ?>
What do you get if you var_dump $act immediately afterwards?

Re: who can tell me what it's meaning of the following code?

Posted: Thu Apr 09, 2009 12:21 pm
by jayshields
I thought I'd test it as I thought it could actually be doing something useful.

I think it's intended as a quick and dirty version of

Code: Select all

if(isset($act)) $act = 'view';
This script

Code: Select all

<?php
$act && $act = 'view';
var_dump($act);
?>
produces

Code: Select all

Notice: Undefined variable: act in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\act.php on line 2
Notice: Undefined variable: act in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\act.php on line 3
NULL
Whereas...

This script

Code: Select all

<?php
$act = 'x';
$act && $act = 'view';
var_dump($act);
?>
produces

Code: Select all

string(4) "view"

Re: who can tell me what it's meaning of the following code?

Posted: Thu Apr 09, 2009 12:53 pm
by Benjamin
It would appear to me to be the source of a bug.

Most likely it should be:

Code: Select all

 
<?php $act && $act == 'view'; ?>
 
This would test that $act is not empty, 0 or false and then verify that it is equal to the string 'view'.