mirror of
https://github.com/php/php-src.git
synced 2024-09-22 10:27:25 +00:00
Test behaviour of weak type hints with references
This commit is contained in:
parent
187a95f8d3
commit
0af3b7c017
29
Zend/tests/typehints/scalar_weak_reference.phpt
Normal file
29
Zend/tests/typehints/scalar_weak_reference.phpt
Normal file
@ -0,0 +1,29 @@
|
||||
--TEST--
|
||||
Weak scalar type hints, with references
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
// implicitly weak mode code
|
||||
|
||||
function to_int(int &$x) {}
|
||||
function to_float(float &$x) {}
|
||||
function to_string(string &$x) {}
|
||||
function to_bool(bool &$x) {}
|
||||
|
||||
$x = 1.0;
|
||||
var_dump($x);
|
||||
to_int($x); // because $x is by-reference, the weak type hint converts it
|
||||
var_dump($x);
|
||||
to_float($x);
|
||||
var_dump($x);
|
||||
to_string($x);
|
||||
var_dump($x);
|
||||
to_bool($x);
|
||||
var_dump($x);
|
||||
?>
|
||||
--EXPECT--
|
||||
float(1)
|
||||
int(1)
|
||||
float(1)
|
||||
string(1) "1"
|
||||
bool(true)
|
Loading…
Reference in New Issue
Block a user