<?php $act && $act = 'view'; ?>
$act is a string.
Thank you.
who can tell me what it's meaning of the following code?
Moderator: General Moderators
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: who can tell me what it's meaning of the following code?
Without testing I assume all it does is assign 'view' to $act.
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: who can tell me what it's meaning of the following code?
What do you get if you var_dump $act immediately afterwards?addaddc wrote:<?php $act && $act = 'view'; ?>
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: who can tell me what it's meaning of the following code?
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
This scriptproduces
Whereas...
This scriptproduces
I think it's intended as a quick and dirty version of
Code: Select all
if(isset($act)) $act = 'view';Code: Select all
<?php
$act && $act = 'view';
var_dump($act);
?>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
NULLThis script
Code: Select all
<?php
$act = 'x';
$act && $act = 'view';
var_dump($act);
?>Code: Select all
string(4) "view"Re: who can tell me what it's meaning of the following code?
It would appear to me to be the source of a bug.
Most likely it should be:
This would test that $act is not empty, 0 or false and then verify that it is equal to the string 'view'.
Most likely it should be:
Code: Select all
<?php $act && $act == 'view'; ?>