Skip to content

Commit 1fd3f5b

Browse files
committed
Implement first-class callable syntax
See https://wiki.php.net/rfc/first_class_callable_syntax
1 parent 3763238 commit 1fd3f5b

File tree

5 files changed

+11
-4
lines changed

5 files changed

+11
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"keywords": ["module", "xp"],
88
"require" : {
99
"xp-framework/core": "^10.0 | ^9.0 | ^8.0 | ^7.0",
10-
"xp-framework/ast": "^7.3",
10+
"xp-framework/ast": "dev-feature/first_class_callable_syntax as 7.4.0",
1111
"php" : ">=7.0.0"
1212
},
1313
"require-dev" : {

src/main/php/lang/ast/emit/PHP.class.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,13 @@ protected function emitNewClass($result, $new) {
988988
array_shift($result->type);
989989
}
990990

991+
protected function emitCallable($result, $callable) {
992+
$t= $result->temp();
993+
$result->out->write('fn(...'.$t.') => ');
994+
$this->emitOne($result, $callable->expression);
995+
$result->out->write('(... '.$t.')');
996+
}
997+
991998
protected function emitInvoke($result, $invoke) {
992999
$this->emitOne($result, $invoke->expression);
9931000
$result->out->write('(');

src/main/php/lang/ast/emit/PHP70.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @see https://wiki.php.net/rfc#php_70
99
*/
1010
class PHP70 extends PHP {
11-
use OmitPropertyTypes, OmitConstModifiers;
11+
use OmitPropertyTypes, OmitConstModifiers, CallablesAsClosures;
1212
use RewriteNullCoalesceAssignment, RewriteLambdaExpressions, RewriteMultiCatch, RewriteClassOnObjects, RewriteExplicitOctals;
1313

1414
/** Sets up type => literal mappings */

src/main/php/lang/ast/emit/PHP71.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @see https://wiki.php.net/rfc#php_71
99
*/
1010
class PHP71 extends PHP {
11-
use OmitPropertyTypes;
11+
use OmitPropertyTypes, CallablesAsClosures;
1212
use RewriteNullCoalesceAssignment, RewriteLambdaExpressions, RewriteClassOnObjects, RewriteExplicitOctals;
1313

1414
/** Sets up type => literal mappings */

src/main/php/lang/ast/emit/PHP72.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @see https://wiki.php.net/rfc#php_72
99
*/
1010
class PHP72 extends PHP {
11-
use OmitPropertyTypes;
11+
use OmitPropertyTypes, CallablesAsClosures;
1212
use RewriteNullCoalesceAssignment, RewriteLambdaExpressions, RewriteClassOnObjects, RewriteExplicitOctals;
1313

1414
/** Sets up type => literal mappings */

0 commit comments

Comments
 (0)