|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2002-04-26 12:09 UTC] msopacua at idg dot nl
 Would be nice if this worked. But the short syntax isn't accepted for a static var, even it's not in the initial declaration.
<?php
function sql_num_rows($result)
{
    static $cmd='undefined';
    if($cmd == 'undefined')
    {
        $cmd=($this->pg_new_api) ? 'pg_num_rows' : 'pg_numrows';
    }
    return @$cmd($result);
}
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 03:00:01 2025 UTC | 
I backtraced my sources and I seem to have combined the fact that arithmetic expressions can't be used on static vars, with the short if-statement. Besides the code I submited, I also used: <?php function testint($row=-1) { static $currentrow=-1; $currentrow=($row == -1) ? $currentrow++ : $row; echo "$currentrow\n"; } ?> which didn't increment $currentrow, nor did it issue any warning. When looking for info, I found the user-contributed message: http://www.php.net/manual/en/language.variables.scope.php By tomek@pluton.pl, at 10-Dec-2001: static $var = 2+3; //any expression which lead me to believe that also () ? : expressions wouldn' t work, but it's the actual assignment that is ignored.