parent
de8fdaf464
commit
7cf265cbc7
23 changed files with 546 additions and 52 deletions
@ -0,0 +1,12 @@ |
|||||||
|
<?php |
||||||
|
$xml = simplexml_load_string('<root></root>'); |
||||||
|
var_dump($xml); |
||||||
|
var_dump((bool)$xml); |
||||||
|
|
||||||
|
$obj = new stdClass(); |
||||||
|
var_dump((bool) $obj); |
||||||
|
|
||||||
|
class UserClass {} |
||||||
|
|
||||||
|
$user = new UserClass(); |
||||||
|
var_dump((bool) $user); |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
#[Native] |
||||||
|
class NativeAnyPropertyReference |
||||||
|
{ |
||||||
|
public any $value = null; |
||||||
|
} |
||||||
|
|
||||||
|
function native_any_property_reference(): void |
||||||
|
{ |
||||||
|
$object = new NativeAnyPropertyReference(); |
||||||
|
$reference =& $object->value; |
||||||
|
$reference = 42; |
||||||
|
} |
||||||
@ -0,0 +1,15 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
#[Native] |
||||||
|
class NativeExplicitDestructor |
||||||
|
{ |
||||||
|
public function __destruct() |
||||||
|
{ |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$object = new NativeExplicitDestructor(); |
||||||
|
$object->__destruct(); |
||||||
|
} |
||||||
@ -0,0 +1,12 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
#[Native] |
||||||
|
class NativeForwardA |
||||||
|
{ |
||||||
|
public ?NativeForwardB $next; |
||||||
|
} |
||||||
|
|
||||||
|
function nativeForwardIdentity(?NativeForwardB $value): ?NativeForwardB |
||||||
|
{ |
||||||
|
return $value; |
||||||
|
} |
||||||
@ -0,0 +1,7 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
#[Native] |
||||||
|
class NativeForwardB |
||||||
|
{ |
||||||
|
public ?NativeForwardA $previous; |
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
#[Native] |
||||||
|
class NativeReferencedProperty |
||||||
|
{ |
||||||
|
public int $value = 1; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$object = new NativeReferencedProperty(); |
||||||
|
$reference =& $object->value; |
||||||
|
} |
||||||
@ -0,0 +1,13 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
#[Native] |
||||||
|
class NativeUnsetProperty |
||||||
|
{ |
||||||
|
public int $value = 1; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$object = new NativeUnsetProperty(); |
||||||
|
unset($object->value); |
||||||
|
} |
||||||
@ -0,0 +1,44 @@ |
|||||||
|
--TEST-- |
||||||
|
Native any properties support PHP references without runtime type dispatch |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
#[Native] |
||||||
|
class NativeAnyReference |
||||||
|
{ |
||||||
|
// `mixed` is the PHP spelling of TypePHP's equivalent `any` storage. |
||||||
|
public mixed $value = 1; |
||||||
|
public ?NativeAnyReference $child; |
||||||
|
} |
||||||
|
|
||||||
|
function replaceAny(mixed &$value, mixed $replacement): void |
||||||
|
{ |
||||||
|
$value = $replacement; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$object = new NativeAnyReference(); |
||||||
|
$reference =& $object->value; |
||||||
|
$reference = 'changed'; |
||||||
|
var_dump($object->value); |
||||||
|
|
||||||
|
$object->value = 42; |
||||||
|
var_dump($reference); |
||||||
|
|
||||||
|
$object->child = new NativeAnyReference(); |
||||||
|
$childReference =& $object->child->value; |
||||||
|
replaceAny($childReference, ['native', 'reference']); |
||||||
|
var_dump($object->child->value); |
||||||
|
} |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
string(7) "changed" |
||||||
|
int(42) |
||||||
|
array(2) { |
||||||
|
[0]=> |
||||||
|
string(6) "native" |
||||||
|
[1]=> |
||||||
|
string(9) "reference" |
||||||
|
} |
||||||
@ -0,0 +1,3 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
echo "included\n"; |
||||||
@ -0,0 +1,37 @@ |
|||||||
|
--TEST-- |
||||||
|
Native class: mutually referencing property types use pointer fields and forward declarations |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
function roundTripMutual(?NativeMutualRight $value): ?NativeMutualRight |
||||||
|
{ |
||||||
|
return $value; |
||||||
|
} |
||||||
|
|
||||||
|
#[Native] |
||||||
|
class NativeMutualLeft |
||||||
|
{ |
||||||
|
public string $name = 'left'; |
||||||
|
public ?NativeMutualRight $right; |
||||||
|
} |
||||||
|
|
||||||
|
#[Native] |
||||||
|
class NativeMutualRight |
||||||
|
{ |
||||||
|
public string $name = 'right'; |
||||||
|
public ?NativeMutualLeft $left; |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$left = new NativeMutualLeft(); |
||||||
|
$right = new NativeMutualRight(); |
||||||
|
$left->right = $right; |
||||||
|
$right->left = $left; |
||||||
|
|
||||||
|
echo roundTripMutual($left->right)->name, ':', $right->left->name, "\n"; |
||||||
|
} |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
right:left |
||||||
@ -0,0 +1,40 @@ |
|||||||
|
--TEST-- |
||||||
|
Native class: direct writes support chained and expression receivers |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
#[Native] |
||||||
|
class NativeWriteNode |
||||||
|
{ |
||||||
|
public int $value; |
||||||
|
public ?NativeWriteNode $child; |
||||||
|
|
||||||
|
public function __construct(int $value) |
||||||
|
{ |
||||||
|
$this->value = $value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function makeNativeWriteNode(int $value): NativeWriteNode |
||||||
|
{ |
||||||
|
return new NativeWriteNode($value); |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$root = new NativeWriteNode(1); |
||||||
|
$root->child = new NativeWriteNode(2); |
||||||
|
$leaf = new NativeWriteNode(3); |
||||||
|
|
||||||
|
$root->child->child = $leaf; |
||||||
|
echo $root->child->child->value, "\n"; |
||||||
|
|
||||||
|
$replacement = new NativeWriteNode(4); |
||||||
|
makeNativeWriteNode(5)->child = $replacement; |
||||||
|
echo $replacement->value, "\n"; |
||||||
|
} |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
3 |
||||||
|
4 |
||||||
@ -0,0 +1,29 @@ |
|||||||
|
--TEST-- |
||||||
|
Native class: shell command interpolation uses the declared toString method |
||||||
|
--SKIPIF-- |
||||||
|
<?php |
||||||
|
if (PHP_OS_FAMILY === 'Windows') { |
||||||
|
die('skip shell command is POSIX-specific'); |
||||||
|
} |
||||||
|
?> |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
#[Native] |
||||||
|
class NativeShellCommand |
||||||
|
{ |
||||||
|
public function toString(): string |
||||||
|
{ |
||||||
|
return 'printf native-shell'; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$command = new NativeShellCommand(); |
||||||
|
echo `$command`, "\n"; |
||||||
|
} |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
native-shell |
||||||
@ -0,0 +1,34 @@ |
|||||||
|
--TEST-- |
||||||
|
Native class: include and eval operands use the declared toString method |
||||||
|
--FILE-- |
||||||
|
<?php |
||||||
|
|
||||||
|
#[Native] |
||||||
|
class NativeStringOperand |
||||||
|
{ |
||||||
|
public string $value; |
||||||
|
|
||||||
|
public function __construct(string $value) |
||||||
|
{ |
||||||
|
$this->value = $value; |
||||||
|
} |
||||||
|
|
||||||
|
public function toString(): string |
||||||
|
{ |
||||||
|
return $this->value; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
function main(): void |
||||||
|
{ |
||||||
|
$path = new NativeStringOperand(__DIR__ . '/include-native-path.inc'); |
||||||
|
include $path; |
||||||
|
|
||||||
|
$source = new NativeStringOperand('echo "evaluated\\n";'); |
||||||
|
eval($source); |
||||||
|
} |
||||||
|
|
||||||
|
?> |
||||||
|
--EXPECT-- |
||||||
|
included |
||||||
|
evaluated |
||||||
Loading…
Reference in new issue