Edit report at http://bugs.php.net/bug.php?id=52439&edit=1
ID: 52439
Comment by: shiranai7 at hotmail dot com
Reported by: shiranai7 at hotmail dot com
Summary: Static and non-static variable name collision in a
class declaration
Status: Bogus
Type: Bug
Package: Class/Object related
Operating System: Win
PHP Version: 5.3.3
New Comment:
I understand, thank you for your answer. This is what the first answer
should have been like.
I'm sorry but this one is about hundred times more valuable than the
other which very nicely says "you are noob and go whine somewhere else".
Previous Comments:
------------------------------------------------------------------------
[2010-07-25 18:31:54] [email protected]
Do any of the scripting languages support static class var separation?
I can't
think of any that do off the top of my head, so I am surprised that you
would
expect this from a scripting language.
------------------------------------------------------------------------
[2010-07-25 18:25:27] [email protected]
We have one property table per class. And a property in a class can have
a static flag, so there can't be two of that name, there are things like
reflection which depend on this. This is expected and won't change.
Sorry if you don't like it.
------------------------------------------------------------------------
[2010-07-25 18:17:07] shiranai7 at hotmail dot com
Not a bug? What is this supposed to be then? Correct behavior? I think
not. This is not a "support question". I am just reporting that PHP
behaves wrong - treats static and non-static variable as one in first
example.
Do I really have to explain that static variable is not THE SAME as
non-static variable and that I am NOT redeclaring anything? Duh.
And - if you are about to reply with another silly predefined answer
then better don't answer at all, thank you.
------------------------------------------------------------------------
[2010-07-25 17:50:44] [email protected]
Sorry, but your problem does not imply a bug in PHP itself. For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. Due to the volume
of reports we can not explain in detail here why your report is not
a bug. The support channels will be able to provide an explanation
for you.
Thank you for your interest in PHP.
------------------------------------------------------------------------
[2010-07-25 17:48:33] shiranai7 at hotmail dot com
Description:
------------
It seems impossible to have two variables - one static and one not -
with same name in a class declaration. But these are two completely
different variables!
Test script:
---------------
<?php
// this results in a fatal error
class Test {
public static $Foo = 'iamstatic';
public $Foo = 'iamNOTstatic';
}
// this works
class Test {
public static $Foo = 'iamstatic';
}
$Baz = new Test();
$Baz->Foo = 'iamNOTstatic';
echo $Baz->Foo."\n";
echo Test::$Foo;
/* Result:
iamNOTstatic
iamstatic
*/
?>
Expected result:
----------------
No errors.
Actual result:
--------------
Fatal error: Cannot redeclare Test::$Foo in *path* on line 6
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52439&edit=1