note 56451 added to function.runkit-class-adopt

From: Date: Fri, 02 Sep 2005 22:09:45 +0000
Subject: note 56451 added to function.runkit-class-adopt
Groups: php.notes 
Request: Send a blank email to php-notes+get-94677@lists.php.net to get a copy of this message
Function visibility (in PHP5) has some quirks as compared to the normal behavior with "extends". Consider the following: class base { public function a() { $this->b(); } private function b() { echo "This is b()"; } } This will work fine: class inherit extends base { public function c() { $this->a(); } } $x = new inherit; $x->c(); while this: class adopt { public function c() { $this->a(); } } runkit_class_adopt('adopt','base'); $x = new adopt; $x->c(); will generate a fatal "Call to private method base::b() from context 'adopt'" error. Protected members can be called from the inherited methods, but still cannot be called from the original class (i.e. if b() were declared protected, the example would work as written, but adopt::c() still could not call base::b() directly. ---- Manual Page -- http://www.php.net/manual/en/function.runkit-class-adopt.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56451 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56451&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56451&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56451&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56451&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56451&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56451&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56451&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94677) next »