Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

PHP Fatal error: Call to protected method MyClass::getSomething() from context 'MyClass' #484

Closed
WWL-MikeRoberts opened this issue Sep 11, 2015 · 2 comments
Labels

Comments

@WWL-MikeRoberts
Copy link

So it took me two days to parse through the code base and get this simple code that still produces the same error. I do not understand pthreads enough to know why this is happening. It's not possible for me to re-arrange where classes are loaded as the actual project code is using an autoloader but I did notice if the require for MyClass is moved to the top level it behaves as expected or if the MyClass definition is put directly into the test script the correct behavior is achieved. Additionally, if the MyTrait definition is moved above the MyWork definition it works as expected as well, regardless of where MyClass is or how it is accessed.

Test Script:

<?php
class MyWork extends \Collectable {
        use \MyTrait;

        public function run() {
                $this->getSomething();
        }
}

trait MyTrait {
        protected function getSomething($test = false) {
                if (!$test) {
                    require_once 'MyClass.php';
                    (new \MyClass())->doSomething();
                }
        }
}

$pool = new \Pool(1, \Worker::class);
$pool->submit(new MyWork());

sleep(5);

$pool->collect(function($work) {
    print_r($work->getTerminationInfo());
});

MyClass.php:

<?php

class MyClass {
    use \MyTrait;

    public function doSomething() {
        $this->getSomething(true);

        print 'DID SOMETHING';
    }
}

Running the test script results in the worker thread throwing
PHP Fatal error: Call to protected method MyClass::getSomething() from context 'MyClass'

krakjoe added a commit that referenced this issue Sep 11, 2015
@krakjoe
Copy link
Owner

krakjoe commented Sep 11, 2015

Thanks for report :)

@krakjoe krakjoe added the bug label Sep 11, 2015
@WWL-MikeRoberts
Copy link
Author

Thank you for the fast resolution!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants