php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66466 Derived classes get wong context
Submitted: 2014-01-11 16:59 UTC Modified: 2014-01-11 18:49 UTC
From: post-christian at freenet dot de Assigned: krakjoe (profile)
Status: Closed Package: pthreads (PECL)
PHP Version: 5.5.8 OS: openSUSE 11.4
Private report: No CVE-ID: None
 [2014-01-11 16:59 UTC] post-christian at freenet dot de
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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [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
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

This is fixed in git master. http://github.com/krakjoe/pthreads

A release is coming, soon ...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 17:01:31 2024 UTC