Page 1 of 1

callback syntax not valid in phalanger tools for VS

PostPosted: March 10th, 2013, 7:26 pm
by carlosqt
Hi there,

The following syntax is not valid neither for Phalanger nor PHP using the Phalanger Tools for VS (for VS2012) version 3.0.4069.

Code: Select all
<?php
echo "Hello World!\n";
fgets(STDIN);

$callback = function myCallbackFunction()
{
echo "callback achieved";
}
call_user_func($callback);
?>


The error is:
Syntax error: unexpected token 'myCallbackFunction'

Is the same for either PHP or Phalanger Console Application project.

Is this a bug in the PHP tools or are PHP callbacks not supported?

Thanks

Carlos

Re: callback syntax not valid in phalanger tools for VS

PostPosted: March 10th, 2013, 8:22 pm
by Jakub Misek
Hi Carlos!

I've checked this syntax with regular PHP (5.4.0), and it does not seem to support such syntax either.

Anonymous functions do not need the function name (http://php.net/manual/en/functions.anonymous.php).

Is it correct?

Thanks!

Re: callback syntax not valid in phalanger tools for VS

PostPosted: March 10th, 2013, 9:12 pm
by carlosqt
Thanks for the quick answer Jakub,

If I remove the function name it works fine thanks!
I will just remove those names whenever I see code like the one with function name.

I'm following a PHP book called "Programming PHP 3rd Edition from O'Reilly" and it seems to be based on version 5.x because of the following statements:
"This book has been fully revised to cover the latest features of PHP version 5."
"As this book goes to press, PHP version 5.4 has been released for some time."


Here below other 3 code examples using that syntax (which includes the function name), however, there is also an example of Anonymous Functions and those do not have function name...

Code: Select all
$callback = function printRow($value, $key)
{
print("<tr><td>{$value}</td><td>{$key}</td></tr>\n");
};
$person = array('name' => "Fred", 'age' => 35, 'wife' => "Wilma");
array_walk($person, $callback);


$callback = function addItUp($runningTotal, $currentValue)
{
$runningTotal += $currentValue * $currentValue;
return $runningTotal;
};
$numbers = array(2, 3, 5, 7);
$total = array_reduce($numbers, $callback);


$callback = function isOdd ($element)
{
return $element % 2;
};
$numbers = array(9, 23, 24, 27);
$odds = array_filter($numbers, $callback);

Re: callback syntax not valid in phalanger tools for VS

PostPosted: March 10th, 2013, 9:25 pm
by Jakub Misek
It is weird, since it seams it is not valid PHP syntax. Maybe some future feature?

Re: callback syntax not valid in phalanger tools for VS

PostPosted: March 11th, 2013, 8:41 am
by carlosqt
Yes, is probably that.
Never mind then and thanks for the clarification.

Carlos

Re: callback syntax not valid in phalanger tools for VS

PostPosted: November 25th, 2013, 5:52 am
by erum
May I ask how does it involve Phalanger Tools? Is there any more information?

Re: callback syntax not valid in phalanger tools for VS

PostPosted: November 25th, 2013, 3:57 pm
by Jakub Misek
Phalanger Tools support the syntax you actually have in currently installed version of Phalanger.