From:             [EMAIL PROTECTED]
Operating system: RedHat 8.0
PHP version:      4.2.2
PHP Bug Type:     Zend Engine 2 problem
Bug description:  strange behaviour regarding $this

We have found a strange behaviour regarding $this. One of our programmers
made a mistake during programming, which led to "Heisenbugs", which were
not quite easy to find and fix. We could reduce the problem to a simple
program to present it:

<?

class Foo {

  var $bla;

  function quux() {
    $this->bla = 5;
  }

}

class Bar {

  var $bla;

  function do_stuff() {
    $this->bla = 10;
    Foo::quux();
    echo $this->bla;
  }
}

$blabla = new Bar;

$blabla->do_stuff();

?>

The output is: "5"

Obviously, Bar::do_stuff() is not allowed to call Foo::quux() since
Foo::quux() is using $this. Now the strange thing comes: instead of
casting an error, PHP happily accepts the code. But the $this in Foo::quux
is the same $this as in Bar::do_stuff(), i.e. $blabla, and that's why the
output is 5. Is this behaviour intended? At least I couldn't find it
documented anywhere. IMO the user should be warned when $this is used in a
static function.
-- 
Edit bug report at http://bugs.php.net/?id=20760&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=20760&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=20760&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=20760&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=20760&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=20760&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=20760&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=20760&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=20760&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=20760&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=20760&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=20760&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=20760&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=20760&r=isapi

Reply via email to