Skip to content

tsantos84/static-members-pthread

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Static Members

This project reproduces the issue when using static members in PHP threads. For some reason, the static members of a class is not accessible when accessed in thread context (e.g: \Thread::run() method).

Sample Code

require 'MyClass.php';
require 'MyThread.php';

var_dump(MyClass::$data); // prints the array properly

$thread = new MyThread();

$thread->start() && $thread->join();

Expected output

array(2) {
  ["foo"]=>
  string(3) "bar"
  ["bar"]=>
  string(3) "baz"
}
array(2) {
  ["foo"]=>
  string(3) "bar"
  ["bar"]=>
  string(3) "baz"
}

Current output

array(2) {
  ["foo"]=>
  string(3) "bar"
  ["bar"]=>
  string(3) "baz"
}
NULL

Building the PHP Docker Images

Run the below code to create an image with PHP 5.6 with pthreads enabled.

$ docker build --rm -t pthreads:php56 .

Run the below code to create an image with PHP 7 with pthreads enabled.

$ docker build --rm -f Dockerfile.php7 -t pthreads:php7 .

Running the sample code

$ ./php56 sample.php

$ ./php7 sample.php

Issue tracking

  • GitHub - As the issues was found using the composer autoloader inside the thread
  • PHP Bugs

About

This project reproduces the issue when using static members in PHP threads.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published