Php Error Call To Protected Method
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site call to protected method php About Us Learn more about Stack Overflow the company Business Learn more about
Call To Private Method From Context Php
hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join php reflection method invoke the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up 'Fatal error call to php reflectionmethod private method' but method is protected up vote 2 down vote favorite 1 First time extending a class in PHP and I'm getting a fatal error that says the method is private when it's not. I'm sure it's something elementary, but I've studied books and forums, and I just can't pin down what I've done to generate this error. Any help greatly appreciated. Details below:
Protected Function Php
Error message: Fatal error: Call to private method testgiver::dbConnect() from context 'testprinter' in /root/includes/classes/testprinter.php on line 726 Line 726 of testprinter in the code below: private function buildquestionarray() { $query = "etc etc"; **$conn = $this->dbConnect('read'); $result = $conn->query($query); ... Testprinter extends testgiver. Here's the extension of the class: require_once('testgiver.php'); class testprinter extends testgiver {... And the declaration of the method in testgiver: protected function dbConnect($userconnecttype) {... Thanks again! php oop share|improve this question asked Aug 1 '12 at 3:50 jwilner 2,46111127 add a comment| 3 Answers 3 active oldest votes up vote 7 down vote accepted As already Alexander Larikov said that you can't access protected methods from class instance but not only protected methods but also you can't access private methods from class instance. To access a protected method of a parent class from the instance of a subclass you declare a public method in the subclass and then call the protected method of the parent class from the public method of the subclass, i.e. class testgiver{ protected function dbConnect($userconnecttype) { echo "dbConnect called with the argument ".$userconnecttype ."!"; } } class testprinter extends testgiver { public function buildquestionarray() // public instead
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta php invoke Discuss the workings and policies of this site About Us Learn php reflection class more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, http://stackoverflow.com/questions/11752327/fatal-error-call-to-private-method-but-method-is-protected helping each other. Join them; it only takes a minute: Sign up Can I/How to… call a protected function outside of a class in PHP up vote 2 down vote favorite 2 I have a protected function that is defined within a certain class. I want to be able to call this protected function outside of the http://stackoverflow.com/questions/17174139/can-i-how-to-call-a-protected-function-outside-of-a-class-in-php class within another function. Is this possible and if so how may I achieve it class cExample{ protected function funExample(){ //functional code goes here return $someVar }//end of function }//end of class function outsideFunction(){ //Calls funExample(); } php function call protected share|improve this question asked Jun 18 '13 at 16:26 Terry Hoverter 1313 1 You can't. That'd defeat the purpose of having a protected function in the first place. You could have a public method which invokes the protected method on your behalf, but then why have a protected method to begin with? –Marc B Jun 18 '13 at 16:30 A duplicate of stackoverflow.com/q/12255740/2088851 –Voitcus Jun 18 '13 at 16:34 add a comment| 5 Answers 5 active oldest votes up vote 5 down vote accepted That's the point of OOP - encapsulation: Private Only can be used inside the class. Not inherited by child classes. Protected Only can be used inside the class and child classes. Inherited by child classes. Public Can be used anywhere. Inher
Sign in Pricing Blog Support Search GitHub This repository Watch 206 Star 2,181 Fork 370 krakjoe/pthreads Code Issues 17 Pull requests 1 Projects 0 Pulse Graphs New issue https://github.com/krakjoe/pthreads/issues/487 PHP Fatal error: Call to protected method MyIterator::myProtectedMethod() from context 'MyIterator' #487 Closed Brewhaus32 opened this Issue Sep 16, 2015 · 6 comments Projects None yet Labels bug Milestone No milestone Assignees No one assigned 2 participants Brewhaus32 commented Sep 16, 2015 Same idea as bug #484 I am using the latest code on the master branch. I noticed it call to with an iterator implementation, not sure if there are other places that have this problem. Only happens if you've had an instance of the class and traversed it before creating a thread that does the same. items = array("joe", "bob", "fred"); $this->position = 0; } public function next() { ++$this->position; call to protected } public function key() { return $this->position; } public function current() { return $this->items[$this->position]; } public function valid() { return ($this->position < count($this->items)); } public function rewind() { $this->myProtectedMethod(); $this->position = 0; } protected function myProtectedMethod() { } } class MyThread extends \Thread { public function run() { $items = new \MyIterator(); foreach ($items as $item) {} print "SUCCESS"; } } $items = new \MyIterator(); foreach ($items as $item) {} $thread = new \MyThread(); $thread->start(); sleep(1); krakjoe added the bug label Sep 17, 2015 Owner krakjoe commented Sep 17, 2015 That does look the same, but it isn't ... it looks like zend_execute_data is caching the class entry from the last thread ... just finding out how to fix it ... Just for my own notes, this only happens when you implement an iterator it seems ... EG(scope) in the new thread is somehow set to the class entry in the main thread ... which is wrong, and it was definitely reset during init ... still looking ... I'll probably have to come back to this later today ... sorry about the wait ... krakjoe added a commit tha