Type ‣ Undefined ᴾᴴᴾ - chung-leong/zigar GitHub Wiki
JavaScript | PHP
The literal undefined in Zig is represented as null in PHP. You will only
encounter it if you explicitly export undefined.
pub const Undefined = undefined;
<?php
$m = zigar_use(__DIR__ . '/undefined-example-1.zig');
debug_zval_dump($m->undefined_value);
NULL
Assigning undefined to a variable would not yield undefined on the JavaScript side.
pub var number: i32 = undefined;
<?php
$m = zigar_use(__DIR__ . '/undefined-example-2.zig');
debug_zval_dump($m->number);
int(0)
As @TypeOf(undefined) is a comptime type, you can only put it into a struct if
you make it a comptime field:
pub const NumberAndUnknown = struct {
number: i32,
comptime unknown: @TypeOf(undefined) = undefined,
};
<?php
$m = zigar_use(__DIR__ . '/undefined-example-3.zig');
$struct = new $m->NumberAndUnknown(number: 1234);
print_r($struct);
NumberAndUnknown Object
(
[number] => 1234
[unknown] =>
)
It's different from void, which is a runtime type.