|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-05-28 12:55 UTC] murray at focus-computing dot com dot au
Description:
------------
A value is assigned to $GLOBALS["now"], however this is removed when a value is assigned to $now, as in the example below
Test script:
---------------
$GLOBALS["now"] = time();
print "Year is " . strftime("%Y", $GLOBALS["now"]) . "\n";
$now = new DateTime("now");
print "Year is " . strftime("%Y", $GLOBALS["now"]) . "\n";
Expected result:
----------------
Year is 2020
Year is 2020
Actual result:
--------------
Year is 2020
<br /> <b>Warning</b>: strftime() expects parameter 2 to be int, object given in <b>[...][...]</b> on line <b>10</b><br /> Year is
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 20:00:01 2025 UTC |
$GLOBALS["now"] and $now are the same variable in the global scope and there is no point to write $GLOBALS at all outside functions <?php $GLOBALS["now"] = time(); print "Year is " . strftime("%Y", $GLOBALS["now"]) . "\n"; $now = new DateTime("now"); print "Year is " . strftime("%Y", $GLOBALS["now"]) . "\n"; ?> versus <?php test(); function test() { $GLOBALS["now"] = time(); print "Year is " . strftime("%Y", $GLOBALS["now"]) . "\n"; $now = new DateTime("now"); print "Year is " . strftime("%Y", $GLOBALS["now"]) . "\n"; } ?>