Bug #79647 [Com]: Conflict between $GLOBALS["now"] and $now

From: Date: Thu, 28 May 2020 13:45:07 +0000
Subject: Bug #79647 [Com]: Conflict between $GLOBALS["now"] and $now
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227220@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79647&edit=1

 ID:                 79647
 Comment by:         bugreports at gmail dot com
 Reported by:        murray at focus-computing dot com dot au
 Summary:            Conflict between $GLOBALS["now"] and $now
 Status:             Not a bug
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   All
 PHP Version:        7.3.18
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

$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";
}
?>


Previous Comments:
------------------------------------------------------------------------
[2020-05-28 13:08:28] cmb@php.net

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php

See <https://www.php.net/manual/en/reserved.variables.globals.php>.

------------------------------------------------------------------------
[2020-05-28 12:55:23] 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



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=79647&edit=1


Thread (9 messages)

« previous php.bugs (#227220) next »