chore(deps): update swoole/phpx dependency and add magic method tests

- Updated swoole/phpx from ~2.4.3 to ~2.4.5 in composer.json
- Added new test case for static::class runtime called scope behavior
- Added new test case for magic method indirect property update using __get by reference
- Extended existing magic method tests with isset true scenario that skips reading
pull/45/head
韩天峰 3 weeks ago
parent a7b16dc1be
commit 6d7e68a9ff
  1. 2
      composer.json
  2. 27
      tests/compiler/class/get-called-class.phpt
  3. 41
      tests/compiler/magic_methods/indirect-update.phpt
  4. 22
      tests/compiler/magic_methods/read-skips-isset.phpt

@ -12,7 +12,7 @@
"marcj/topsort": "^2.0",
"symfony/var-dumper": "^8.0",
"symfony/yaml": "^8.0",
"swoole/phpx": "~2.4.3",
"swoole/phpx": "~2.4.5",
"ajaxray/ansikit": "^0.3.1"
},
"require-dev": {

@ -0,0 +1,27 @@
--TEST--
static::class uses the runtime called scope
--FILE--
<?php
declare(strict_types=1);
class CalledClassParent
{
public static function name(): string
{
return static::class;
}
}
class CalledClassChild extends CalledClassParent
{
}
function main(): void
{
var_dump(CalledClassParent::name());
var_dump(CalledClassChild::name());
}
?>
--EXPECT--
string(17) "CalledClassParent"
string(16) "CalledClassChild"

@ -0,0 +1,41 @@
--TEST--
Magic Methods - indirect property update uses __get by reference
--FILE--
<?php
declare(strict_types=1);
class MagicUpdateTest
{
private array $values = [];
public function __isset(string $name): bool
{
echo "__isset($name)\n";
return false;
}
public function &__get(string $name): mixed
{
echo "__get($name)\n";
return $this->values[$name];
}
public function value(string $name): mixed
{
return $this->values[$name] ?? null;
}
}
function main(): void
{
$probe = new MagicUpdateTest();
$probe->value[] = 42;
var_dump($probe->value('value'));
}
?>
--EXPECT--
__get(value)
array(1) {
[0]=>
int(42)
}

@ -21,6 +21,21 @@ class MagicReadTest
}
}
class MagicIssetTrueTest
{
public function __isset(string $name): bool
{
echo "__isset($name)\n";
return true;
}
public function __get(string $name)
{
echo "__get($name)\n";
return null;
}
}
function main(): void
{
$obj = new MagicReadTest();
@ -33,6 +48,10 @@ function main(): void
echo "--- empty ---\n";
var_dump(empty($obj->aaa));
echo "--- isset true does not read ---\n";
$issetTrue = new MagicIssetTrueTest();
var_dump(isset($issetTrue->value));
}
?>
--EXPECTF--
@ -45,3 +64,6 @@ bool(false)
--- empty ---
__isset(aaa)
bool(true)
--- isset true does not read ---
__isset(value)
bool(true)

Loading…
Cancel
Save