Doc #60375 [Com]: Accessibility between classes

From: Date: Fri, 25 Nov 2011 17:20:17 +0000
Subject: Doc #60375 [Com]: Accessibility between classes
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-7470@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=60375&edit=1 ID: 60375 Comment by: luraschigabriel at gmail dot com Reported by: luraschigabriel at gmail dot com Summary: Accessibility between classes Status: Bogus Type: Documentation Problem Package: Class/Object related Operating System: Windows XP SP3 PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: Ohhhh thanks, it's logic... Please delete this bug report. Regards, Previous Comments: ------------------------------------------------------------------------ [2011-11-25 04:53:06] laruence@php.net you are attemptting to call a protected constructor from a outside scope. just like: abstract class A { protected function __construct() { echo "A constructor\n"; } } class B extends A { /* NO __construct() declared */ public function foo() { echo "foo method"; } } new B();//PHP Fatal error: Call to protected A::__construct() from invalid context if you want B have a non-protected constructor, you must redeclared it with 'public'. ------------------------------------------------------------------------ [2011-11-24 20:52:16] luraschigabriel at gmail dot com Description: ------------ When a construct is not declared on a inherited class and it's declared on base class as protected, an instantiation of the derived class inside another class, causes a fatal accessibility error. Test script: --------------- abstract class A { protected function __construct() { echo "A constructor\n"; } } class B extends A { /* NO __construct() declared */ public function foo() { echo "foo method"; } } class C { public $B; function __construct() { $this->B = new B(); // Produces an error because B has no construct declared. } } $c = new C(); Expected result: ---------------- This behavior is not documented. Actual result: -------------- Error: document.php line 18 - Call to protected A::__construct() from context 'C'. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60375&edit=1

« previous php.doc.bugs (#7470) next »