Skip to content
Closed
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
31 changes: 31 additions & 0 deletions Zend/tests/instance_invoke_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
Instance invoke
--FILE--
<?php

class Foo
{
public function __invoke() {
echo "okey";
}
}

(new Foo())();

class Bar
{
public function __invoke($name) {
return $name;
}
}

var_dump((new Bar())());
var_dump((new Bar())("okey"));

--EXPECTF--
okey
Warning: Missing argument 1 for Bar::__invoke(), called in %sinstance_invoke_001.php on line %d and defined in %sinstance_invoke_001.php on line %d

Notice: Undefined variable: name in %sinstance_invoke_001.php on line %d
NULL
string(4) "okey"
13 changes: 13 additions & 0 deletions Zend/tests/instance_invoke_002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Instance invoke
--FILE--
<?php

class Foo
{
}

(new Foo())();

--EXPECTF--
Fatal error: Function name must be a string in %sinstance_invoke_002.php on line %d
27 changes: 27 additions & 0 deletions Zend/tests/instance_invoke_003.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
Instance invoke
--FILE--
<?php

class Foo
{
public $var = "foo";
public function dummy() {
var_dump(__METHOD__);
}
public function __invoke() {
return $this;
}
public function __get($name) {
return $name;
}
}

(new Foo())()->dummy();
var_dump((new Foo())->var);
var_dump((new Foo())->noexists);

--EXPECT--
string(10) "Foo::dummy"
string(3) "foo"
string(8) "noexists"
2 changes: 2 additions & 0 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ instance_call:
/* empty */ { $$ = $0; }
| { zend_do_push_object(&$0 TSRMLS_CC); zend_do_begin_variable_parse(TSRMLS_C); }
chaining_instance_call { zend_do_pop_object(&$$ TSRMLS_CC); zend_do_end_variable_parse(&$2, BP_VAR_R, 0 TSRMLS_CC); }
| { zend_do_begin_dynamic_function_call(&$0, 0 TSRMLS_CC); }
function_call_parameter_list { zend_do_end_function_call(&$0, &$$, &$2, 0, 1 TSRMLS_CC); zend_do_extended_fcall_end(TSRMLS_C); } instance_call { $$ = $4; }
;

new_expr:
Expand Down