php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30820 static member conflict with $this->member silently ignored
Submitted: 2004-11-18 02:40 UTC Modified: 2005-06-08 10:08 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:0 (0.0%)
From: levi at alliancesoftware dot com dot au Assigned: andi (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS-2005-03-06 OS: *
Private report: No CVE-ID: None
 [2004-11-18 02:40 UTC] levi at alliancesoftware dot com dot au
Description:
------------
 If you declare a static data member (eg x),
$this->x refers to a different variable
without generating any warnings.

 Arguably, the proper behavior when setting
a class variable through $this should first
be to check if there are any static member
variables of the same name and *then* check
for instantiated member variables.

Reproduce code:
---------------
#!/usr/local/bin/php5 -q
<?
// error reporting is set to E_ALL in php.ini
class Blah {
    public static $x;
    public function show() {
        Blah::$x = 1;
        $this->x = 5; // no warning, but refers to different variable

        echo '   Blah::$x = '. Blah::$x ."\n";
        echo '$   this->x = '. $this->x ."\n";
    }
}

$b = new Blah();
$b->show();
?>

Expected result:
----------------
either: (preferable)

   Blah::$x = 5
   $this->x = 5



-or-

 at the minimum, display a warning

Actual result:
--------------

   Blah::$x = 1
   $this->x = 5

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-08 10:08 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC