PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Method Modifiers

pthreads overrides the functionality of the protected and private method modifiers in order to provide functionality more suited to multi-threaded objects. pthreads applies this functionality to all Thread, Worker and Stackable objects from creation.

Example #2 protected method example: protected methods can only be executed by one Thread at a time.

<?php
class ExampleThread extends Thread {
    public function 
run() {
        
/* thread code */
        
if ($this->synchronized()) {

        }
    }

    protected function 
exclusive() {
        
/* synchronized method */
    
}
}

$thread = new ExampleThread();
if (
$thread->start()) {
    
$thread->exclusive();
}
?>

Example #3 private method example: private methods may only be executed by the Thread, Worker, or Stackable during execution

<?php
class ExampleThread extends Thread {
    public function 
run() {
        
/* thread code */
        
if ($this->insideonly()) {

        }
    }

    private function 
insideonly() {
        
/* private method */
    
}
}

$thread = new ExampleThread();
if (
$thread->start()) {
    
$thread->insideonly();
}
?>

PHP Manual