This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Imagine having the following code: <?php $f = function(){}; ($f)(); Putting the callable variable in parentheses is actually valid as of PHP 5.6, but Netbeans marks it as an error, with both PHP 5.6 and 7.0 project settings.
True. Unfortunately, this is quite difficult to fix so as a workaround, simply use "$f()", this should work. Sorry for inconveniences. Thanks.
That workaround only works in that simple case, consider the following example: class Foo { private $callable; public function __construct(callable $callable) { $this->callable = $callable; } public function doSomething() { ($this->callable)(); } } The only workaround to that would be to do this in the method: $callable = $this->callable; $callable(); Which is really quite ugly and requires creating a new reference.
You are right, we know about it. Unfortunately, as I wrote, it is not easy to fix this issue but we will try it, of course. Thanks.
I sadly don't know much about Netbeans source, let alone Java. But could you point me to the file which is responsible of the parsing, so I could take a look at it?
(In reply to dasprid from comment #4) > But could you > point me to the file which is responsible of the parsing, so I could take a > look at it? Sure, its this file [1]. Adding Junichi to CC, he could be maybe interested in fixing of this issue. If not, I will try to have a look at it. Thanks. [1] http://hg.netbeans.org/web-main/file/tip/php.editor/tools/ASTPHP5Parser.cup
I'm not sure whether I can fix it. But I'll try to have a look at it once (later). Thanks.
*** Bug 268100 has been marked as a duplicate of this bug. ***
*** Bug 268163 has been marked as a duplicate of this bug. ***
Created attachment 162235 [details] screenshot I'm looking at this. We may be able to fix it.(I can be wrong.) Could anyone provide more examples((...)())? Is there anyone who has them? Thanks.
Here are a few more: class Bar { public function __invoke() {} } (new Bar())(); (new class { public function __invoke() {} })(); 'strlen'('1');
And another one: class Baz { public static function bat() {} } php > ['Baz', 'bat']();
(In reply to dasprid from comment #10) > Here are a few more: > > class Bar { public function __invoke() {} } > (new Bar())(); > > (new class { public function __invoke() {} })(); > > 'strlen'('1'); (In reply to dasprid from comment #11) > And another one: > > class Baz { public static function bat() {} } > php > ['Baz', 'bat'](); Thank you! They are errors in my change yet. I'll try it again...
(In reply to junichi11 from comment #9) > Created attachment 162235 [details] > screenshot > > I'm looking at this. We may be able to fix it.(I can be wrong.) Seems great, Junichi! Adding 82patch-candidate Whiteboard so it could be part of the patch for NB 8.2. Thanks a lot!
Created attachment 162324 [details] screenshot I fixed the syntax errors for the following code: <?php $func1 = function(){echo "anonymous function1" . PHP_EOL;}; ($func1)(); // anonymous function1 $func2 = function() { return function() {echo "anonymous function2" . PHP_EOL;}; }; (($func2)())(); // anonymous function2 (function(){echo "anonymous function3" . PHP_EOL;})(); // anonymous function3 (function($param1, $param2) {echo "anonymous function4" . PHP_EOL;})("param1", "param2"); // anonymous function4 class Bar { public function __invoke() {echo "class __invoke" . PHP_EOL;} } (new Bar())(); // class __invoke (new Bar)(); // class __invoke (new class { public function __invoke() {echo "anonymous class __invoke" . PHP_EOL;} })(); // anonymous class __invoke echo 'strlen'('scalar call') . PHP_EOL; // 11 $something = 'something'; echo 'strlen'($something) . PHP_EOL; // 9 echo ("strlen")($something) . PHP_EOL; // 9 $a = "strlen"; $b = "a"; echo ($$b)("foo") . PHP_EOL; // 3 class ArrayCall { public static function test() { echo "array call" . PHP_EOL;} } $array = new ArrayCall(); ['ArrayCall', 'test'](); // array call (['ArrayCall', 'test'])(); // array call [new ArrayCall, 'test'](); // array call [new ArrayCall(), 'test'](); // array call array('ArrayCall', 'test')(); // array call array($array, 'test')(); // array call $test = "test"; [new class {public static function test($param) {echo "anonymous class array call" . PHP_EOL;}}, $test]("test"); // anonymous call array call class Foo { private $callable; public function __construct(callable $callable) { $this->callable = $callable; } public function doSomething() { ($this->callable)(); } } But something is missing yet... There is a CC problem. I'll try to fix it. Thanks.
Created attachment 162325 [details] CC problem (In reply to junichi11 from comment #14) > But something is missing yet... There is a CC problem. I'll try to fix it. Sorry, I'm wrong... This also occurs when anonymous functions are used in NB8.1. So, it's another problem.
Now, some existing tests fail. So I'll look at them.
Great job, Junichi! Thanks a lot!
I fixed it. But there is one formatting problem[1] yet. IMHO, it is a minor use case. So, I didn't fix it. Tomas, Which do you prefer? - Attach a patch - Push my changes Should I update version number at the same time? Thanks. [1] <?php [new class {public static function test($param) {echo "anonymous class array call" . PHP_EOL;}}, $test]("test"); Actual: [new class { public static function test($param) { echo "anonymous class array call" . PHP_EOL; } }, $test]("test"); Expected: [new class { public static function test($param) { echo "anonymous class array call" . PHP_EOL; } }, $test]("test");
Fixed. http://hg.netbeans.org/web-main/rev/f93a28afd2e8 Thanks.
Guys, in order to be part of the patch for NB 8.2, could you please verify that this issue is fixed now? Just wait for a message that will appear here saying in which daily build this change will be available. Junichi, great job as always! Thanks!
Integrated into 'main-silver', will be available in build *201610150002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-silver/rev/f93a28afd2e8 User: Junichi Yamamoto <junichi11@netbeans.org> Log: #259111 - [PHP7] Callable variable in parentheses is marked as error
Looks fixed for me.
(In reply to dasprid from comment #22) > Looks fixed for me. Thanks for your verification!
Thanks a lot!
*** Bug 268652 has been marked as a duplicate of this bug. ***
Transplanted to the releases repo branch release82: http://hg.netbeans.org/releases/rev/4d288f1e22ad Thanks.
82patch1-verified