- var_dump: documentation ( source)
<?php
class NullableA {
private function __construct() {}
public ?string $string;
public static function &string(?string $defaultValue = null) {
$type = new self;
$type->string = $defaultValue;
return $type->string;
// type is garbage collected
}
}
class NullableB {
private static $antiGarbageCollect = [];
private function __construct() {}
public ?string $string;
public static function &string(?string $defaultValue = null) {
$type = new self;
self::$antiGarbageCollect[] = $type;
$type->string = $defaultValue;
return $type->string;
}
}
$a =& NullableA::string();
$a = 123;
var_dump($a);
$b =& NullableB::string();
$b = 123;
var_dump($b);