callback syntax not valid in phalanger tools for VS

Phalanger Tools for Visual Studio [?] is complete PHP/Phalanger integration into Visual Studio development environment.

callback syntax not valid in phalanger tools for VS

Postby carlosqt » March 10th, 2013, 7:26 pm

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
carlosqt
 
Posts: 7
Joined: March 10th, 2013, 7:21 pm

Re: callback syntax not valid in phalanger tools for VS

Postby Jakub Misek » March 10th, 2013, 8:22 pm

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!
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: callback syntax not valid in phalanger tools for VS

Postby carlosqt » March 10th, 2013, 9:12 pm

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);
carlosqt
 
Posts: 7
Joined: March 10th, 2013, 7:21 pm

Re: callback syntax not valid in phalanger tools for VS

Postby Jakub Misek » March 10th, 2013, 9:25 pm

It is weird, since it seams it is not valid PHP syntax. Maybe some future feature?
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: callback syntax not valid in phalanger tools for VS

Postby carlosqt » March 11th, 2013, 8:41 am

Yes, is probably that.
Never mind then and thanks for the clarification.

Carlos
carlosqt
 
Posts: 7
Joined: March 10th, 2013, 7:21 pm

Re: callback syntax not valid in phalanger tools for VS

Postby erum » November 25th, 2013, 5:52 am

May I ask how does it involve Phalanger Tools? Is there any more information?
erum
 
Posts: 1
Joined: November 25th, 2013, 5:51 am

Re: callback syntax not valid in phalanger tools for VS

Postby Jakub Misek » November 25th, 2013, 3:57 pm

Phalanger Tools support the syntax you actually have in currently installed version of Phalanger.
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague


Return to Phalanger Tools

Who is online

Users browsing this forum: No registered users and 11 guests

cron

User Control Panel

Login

Who is online

In total there are 11 users online :: 0 registered, 0 hidden and 11 guests (based on users active over the past 5 minutes)
Most users ever online was 256 on March 28th, 2024, 9:42 am

Users browsing this forum: No registered users and 11 guests