|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-01-11 18:49 UTC] krakjoe@php.net
-Status: Open
+Status: Closed
-Assigned To:
+Assigned To: krakjoe
[2014-01-11 18:49 UTC] krakjoe@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 22 05:00:01 2025 UTC |
Description: ------------ Derived classes get wrong context inside the thread. Please see example below. Test script: --------------- abstract class Animal { protected abstract function getName(); public function printName() { echo __CLASS__ . " -> " . $this->getName() . "\n"; } } class Bird extends Animal { protected function getName() { return "Bird"; } } $bird = new Bird(); $bird->printName(); class MyThread extends Thread { private $animal; public function __construct( $animal ) { $this->animal = $animal; } public function run() { $this->animal->printName(); } } $thread = new MyThread( $bird ); $thread->start(); $thread->join(); Expected result: ---------------- The protected function of the derived class should be called like outside the thread. Actual result: -------------- Normal PHP: Animal -> Bird Inside Thread: PHP Fatal error: Call to protected method Bird::getName() from context 'Animal' in thread_test.php on line 7