Special property ‣ __value ᴾᴴᴾ - chung-leong/zigar GitHub Wiki
JavaScript | PHP
The value of the object itself. The main purpose of this property is to allow you to change the object as a whole. For example, suppose you have an instance of the following struct:
pub const Hello = struct {
number1: i32 = 0,
number2: i32 = 0,
number3: i32 = 0,
};
Assignment to __value would basically reinitialize the object:
<?php
$m = zigar_use(__DIR__ . '/value-example-1.zig');
$hello = new $m->Hello(number1: 1000, number2: 2000);
print_r($hello);
$hello->__value = [ 'number3' => 3000 ];
print_r($hello);
Hello Object
(
[number1] => 1000
[number2] => 2000
[number3] => 3
)
Hello Object
(
[number1] => 1
[number2] => 2
[number3] => 3000
)
Note how the fields number1 and number2 reverted to their default values after the assignment.
__value is also the mean by which you can access the value of a standalone scalar:
pub const I32 = i32;
<?php
$m = zigar_use(__DIR__ . '/value-example-2.zig');
$number = new $m->I32(1234);
print_r($number);
print_r($number->__value);
i32 Object
(
[value] => 1234
)
1234
This property is also available under the dollar sign:
<?php
$m = zigar_use(__DIR__ . '/value-example-2.zig');
$number = new $m->I32(1234);
print_r($number);
print_r($number->{'$'});