ID:               37047
 Updated by:       [EMAIL PROTECTED]
 Reported By:      karoly at negyesi dot net
 Status:           Open
-Bug Type:         Variables related
+Bug Type:         Documentation problem
 Operating System: Irrevelant
 PHP Version:      5.1.2
 New Comment:

No, there is a difference between definition and assignment. The
variable is overwritten by the static-call during compilation. The value
is only assigned when the assignment is actually done.

In Jakub's last example, the code never hits the assignment statement.

In the original report, the "static $storage" definition is done twice,
and during the 2nd time the original $storage static definition is
destroyed. The static fetch in the return statement will therefore not
work. I'd say this should be documented...

It wouldn't be hard to add a notice for this though.


Previous Comments:
------------------------------------------------------------------------

[2007-08-20 10:42:39] [EMAIL PROTECTED]

If static variables are resolved in compile time then

<?php
function storage($key) {
  return $storage;
  static $storage = array('a' => array('x', 'y'));
}
var_dump(storage('a'));
?>

should give an expected result.

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

[2006-04-12 08:31:01] [EMAIL PROTECTED]

It's the same as
<?php
exit;
class Test { }
?>
The class will be still declared, even though there is an exit
statement before the declaration. It doesn't mean that it's "executed",
because there is a big difference between "execution" and "compilation".

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

[2006-04-11 22:44:27] karoly at negyesi dot net

Hint. If you doc this please doc everything as well that executes at
compile time. It will be a very interesting handbook page...

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

[2006-04-11 22:38:31] [EMAIL PROTECTED]

Sorry. I misread.

You're right (-:

S


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

[2006-04-11 22:37:29] [EMAIL PROTECTED]

see: http://php.net/return

"the return() statement immediately ends execution of the current
function"

(It's already documented.)

S


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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/37047

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

Reply via email to