Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/capabilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ Auto-generated by `script/capability-matrix.php`. Do not edit by hand.
| `array_filter` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `array_flip` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `array_intersect` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `array_is_list` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `array_key_exists` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `array_key_first` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `array_key_last` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `array_is_list` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `array_keys` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `array_map` | yes | yes | yes | standard | callbacks: null/string builtins; closures deferred (#1154); JIT PHPT; AOT PHPT |
| `array_merge` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
Expand Down Expand Up @@ -277,8 +277,8 @@ Auto-generated by `script/capability-matrix.php`. Do not edit by hand.
| `uasort` | yes | yes | yes | standard | JIT PHPT |
| `ucfirst` | yes | yes | yes | standard | |
| `ucwords` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `uniqid` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `unlink` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `uniqid` | yes | yes | yes | standard | VM/JIT/AOT PHPT (#2219) |
| `unserialize` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `urldecode` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
| `urlencode` | yes | yes | yes | standard | JIT PHPT; AOT PHPT |
Expand Down
19 changes: 12 additions & 7 deletions lib/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,28 +158,33 @@ protected function compileBlock(Block $block) {
}

protected function compileOps(array $ops, Block $block): void {
// First hoist functions and class definitions
// Hoist class-like definitions before functions so JIT/AOT see member
// constants when compiling FUNCDEF bodies (issue #2215, MiniWebApp Router::CONST).
foreach ($ops as $child) {
switch (get_class($child)) {
case Op\Stmt\Function_::class:
$block->addOpCode($this->compileFunction($child, $block));
break;
case Op\Stmt\Class_::class:
$block->addOpCode($this->compileClassLike($child, $block));
break;
case Op\Stmt\Enum_::class:
$block->addOpCode($this->compileEnum($child, $block));
break;
case Op\Terminal\Const_::class:
$block->addOpCode($this->compileGlobalConst($child, $block));
break;
case Op\Stmt\Interface_::class:
$block->addOpCode($this->compileInterface($child, $block));
break;
case Op\Stmt\Trait_::class:
break;
}
}
foreach ($ops as $child) {
switch (get_class($child)) {
case Op\Stmt\Function_::class:
$block->addOpCode($this->compileFunction($child, $block));
break;
case Op\Terminal\Const_::class:
$block->addOpCode($this->compileGlobalConst($child, $block));
break;
}
}
$opCount = count($ops);
for ($i = 0; $i < $opCount; ++$i) {
$child = $ops[$i];
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<file>./test/compliance/VisibilityJitTest.php</file>
<file>./test/compliance/IncludeScopeVMTest.php</file>
<file>./test/compliance/ClassMemberConstVMTest.php</file>
<file>./test/compliance/ClassConstFetchVMTest.php</file>
</testsuite>
<testsuite name="PHPCompiler Unit Test Suites">
<directory suffix=".php">./test/unit</directory>
Expand Down
22 changes: 22 additions & 0 deletions test/compliance/ClassConstFetchVMTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace PHPCompiler;

require_once __DIR__.'/../BaseTest.php';
require_once __DIR__.'/ClassMemberConstVMTest.php';

/**
* VM compliance: user class constant fetch from global functions (#2215).
*/
class ClassConstFetchVMTest extends ClassMemberConstVMTest
{
public static function providePHPTests(): \Generator
{
yield 'class_const_fetch_user.phpt' => self::parsePHPT(
__DIR__.'/cases/classes/class_const_fetch_user.phpt',
'class_const_fetch_user.phpt'
);
}
}
13 changes: 13 additions & 0 deletions test/compliance/cases/classes/class_const_fetch_user.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
User class constant fetch from global function (issue #2215)
--FILE--
<?php
function contact_name_max(): int {
return Router::DEFAULT_CONTACT_NAME_MAX;
}
class Router {
public const DEFAULT_CONTACT_NAME_MAX = 200;
}
echo contact_name_max();
--EXPECT--
200
13 changes: 13 additions & 0 deletions test/fixtures/aot/cases/class_const_fetch_user.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
AOT: user class constant fetch from global function (#2215)
--FILE--
<?php
function contact_name_max(): int {
return Router::DEFAULT_CONTACT_NAME_MAX;
}
class Router {
public const DEFAULT_CONTACT_NAME_MAX = 200;
}
echo contact_name_max();
--EXPECT--
200