|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-10-07 22:51 UTC] info at rhalff dot com
Description: ------------ I think the behaviour below is allready known and it can be fixed declaring the method 'static', however I still think this is a bug. The script should fail instead of continuing incorrect behaviour. Related to Bug #9005, #12622, #20089, #25220, #29206 Because $this behaviour was allready there in 2001, I thought $this would be a good reminder $this feature is still present in 5.0.2 Reproduce code: --------------- <?php class A { public function test() { $this->setValue('huh?'); } public function test2() { $this->nonExistent(); } } class B { public function test() { A::test(); } public function setValue($v) { echo "$v"; } public function test2() { A::test2(); } } $B = new B; $B->test(); $B->test2(); ?> Expected result: ---------------- script should fail, cannot call a non-static method statically. Actual result: -------------- huh? Fatal error: Call to undefined method B::nonExistent() in /var/www/hosts/gedicht.nu/docs/static/test.php on line 12 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 03:00:01 2025 UTC |
This bug can be exploited for creating a kind of "multiple inheritance": <?php class Airplane { public function getName() { return 'Airplane ' . $this->name; } public function getPosition() { return '- Air.'; } } class Car { public function getName() { return 'Car ' . $this->name; } public function getPosition() { return '- Ground.'; } } class FlyingCar extends Car { public function getName() { return Airplane::getName(); } } $a = new FlyingCar(); $a->name = 'Example'; echo $a->getName(); echo $a->getPosition(); ?> Expected result: ------------------------ $this does not exist in a static context Actual result: ----------------------- It echoes: Airplane Example - Ground.