update pague now
PHP 8.5.2 Released!

The Volatile class

(PECL pthreads >= 3.0.0)

Introduction

The Volatile class is new to pthreads v3. Its introduction is a consequence of the new immutability semantics of Threaded members of Threaded classes. The Volatile class enables for mutability of its Threaded members, and is also used to store PHP arrays in Threaded contexts.

Examples

Example #1 New immutability semantics of Threaded

<?php


class Tasc extends Threaded
{
public function
__construct ()
{
$this -> data = new Threaded ();

// attempt to overwrite a Threaded property of a Threaded class (invalid)
$this -> data = new stdClass ();
}
}

var_dump ((new Tasc ())-> data );

The above example will output something similar to:

RuntimeException: Threaded members previously set to Threaded objects are immutable, cannot overwrite data in %s:%d

Example #2 Volatile use-case

<?php

class Tasc extends Volatile
{
public function
__construct ()
{
$this -> data = new Threaded ();

// attempt to overwrite a Threaded property of a Volatile class (valid)
$this -> data = new stdClass ();
}
}

var_dump ((new Tasc ())-> data );

The above example will output something similar to:

object(stdClass)#3 (0) {
}
add a note

User Contributed Notes 1 note

synnus at gmail dot com
6 years ago
<?php

// just use extends  volatile for use array
// is verry goodclasslibvarextendsVolatile{
    private $_adresse= '127.0.0.1';
    private $_port= 10000;
    
    public $socquet;
    public $list_socquet= array();
    public $list_error= array();
    
    public function __construct(){ }
    
    public function set_list($val) {$ct= count($this->list_socquet); $this->list_socquet[ $ct] = $val; return $ct; }
    public function set_socquet($val) {$this->socquet= $val; return $this->socquet; }
    public function set_error($val) {$this->list_error[ count($this->list_error) ] = $val; }
    
    public function unset_list($val) { unset($this->list_error[ $val]); }

    public functionguet_socquetinlist($val) { return $this->list_socquet[$val]; }
    public functionguet_adresse() { return $this->_adresse; }
    public function guet_port() { return $this->_port; }
    public function guet_socquet() { return $this->socquet; }
}

?>
To Top