1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/Zend/tests/assign_obj_to_ref_inference.phpt
2022-04-15 23:00:43 +02:00

43 lines
635 B
PHP

--TEST--
Assigning an object of known type to a reference variable
--FILE--
<?php
class Test {
public int $x = 42;
}
function test1() {
$r =& $o;
$o = new Test;
$r = new stdClass;
$r->x = 3.141;
var_dump(is_float($o->x));
}
function test2($o) {
$r =& $o;
if ($o instanceof Test) {
$r = new stdClass;
$r->x = 3.141;
var_dump(is_float($o->x));
}
}
function test3(Test &$o) {
$GLOBALS['r'] = new stdClass;
$GLOBALS['r']->x = 3.141;
var_dump(is_float($o->x));
}
test1();
test2(new Test);
$r = new Test;
test3($r);
?>
--EXPECT--
bool(true)
bool(true)
bool(true)