Resolution of static variables in the function scope not using forwarded calling information?

From: Date: Mon, 27 Apr 2015 21:12:17 +0000
Subject: Resolution of static variables in the function scope not using forwarded calling information?
Groups: php.internals 
Request: Send a blank email to internals+get-85977@lists.php.net to get a copy of this message
Hello all, I ran into some very strange behavior while experimenting with static function variables. It looks like a bug to me, but I couldn't find any previous reports or discussions about the subject, so I wanted to gather your input before submitting it as such. Static variables in the function scope appear to be resolved using late static binding: the content of the variable in that function is shared amongst all instances of a class, though each subclass gets its own separate variable space. This is pretty logical and works fine. As an example, let's create classes Base => Animal => {Cat,Dog}. Base has a function that describes the class, and caches the result in a static function variable $description. Calling describe() on the three different classes correctly gives us three different results: http://3v4l.org/Qldve However, once you override the describe function in Animal and call parent::describe() from within, it looks like all calling information is lost: the resolution of $description in Base's function scope now always points to Animal's variable space. For example: http://3v4l.org/qWrvf Overriding the function in one of the childmost classes like Dog gives an even stranger result: $description is now correctly a separate value in Cat vs Dog, but calling Animal::describe() now uses the value left by its child class Cat?! See: http://3v4l.org/61P72 Any thoughts? Thanks, Laszlo

« previous php.internals (#85977) next »