|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-12-28 21:07 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 02 17:00:01 2025 UTC |
Description: ------------ I can call a public function like a static function from another class. The variable "$this" refers to the caller. Reproduce code: --------------- <?php class testA{ private $var; public function __construct(){ $this->var = 'Hello'; } public function getVar(){ return $this->var; } public function test(){ return $this->getVar(); } } class testB{ public function test(){ // Should not work! echo testA::test(); } } $myTestB = new testB(); $myTestB->test(); ?> Expected result: ---------------- Error because class testB called a static function that does not exists. Actual result: -------------- Call the static method "getVar()" in class testB. $this refers to testB. PHP Fatal error: Call to undefined method testB::getVar() in /var/www/svnhome/kronos/kronoscrm/test.php on line 15 Fatal error: Call to undefined method testB::getVar() in /var/www/svnhome/kronos/kronoscrm/test.php on line 15