php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52439 Static and non-static variable name collision in a class declaration
Submitted: 2010-07-25 17:48 UTC Modified: 2010-07-25 18:58 UTC
From: shiranai7 at hotmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.3.3 OS: Win
Private report: No CVE-ID: None
 [2010-07-25 17:48 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-25 17:50 UTC] pajoye@php.net
-Status: Open +Status: Bogus
 [2010-07-25 17:50 UTC] pajoye@php.net
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 18:17 UTC] 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 18:25 UTC] johannes@php.net
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:31 UTC] rasmus@php.net
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:38 UTC] shiranai7 at hotmail dot com
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".
 [2010-07-25 18:58 UTC] pajoye@php.net
This is well documented and the comment is a standard comment to mark bug regarding documented features as "not a bug". I'm sorry if the text looks offending but it is not, even if the word "bogus" could be badly misinterpreted.

Also please understand that it is not a support channel and we have many bugs to process, that's why pre defined messages exist.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 22:01:31 2024 UTC