Welcome! Log In Create A New Profile

Advanced

[PHP] Syntax generating error?

Posted by Jeffry Killen 
Jeffry Killen
[PHP] Syntax generating error?
April 01, 2017 11:50PM
Hi;
The following error is generated by the line marked "// << error indicated"

Fatal error: Function name must be a string in dev_lab_current/lab_20/php/arrayRecursorREV-2.php on line 556

self::$_localParams = array
(
'receiver'=>array('value'=>'', 'count'=>0),
'type'=>'',
'current'=>'',
'value'=>'',
'count'=>'',
'len'=>'',
'parent'=>'',
'level'=>0,
'record'=>array(),
'addPath'=>function(){self::showPath();},
'stat'=>array()
);

print self::$_localParams['addPath']().'<br>';// << error indicated (line 556)

This is in an early development stage and the print statement is to test the concept and
the function that is supposed to be called. If the function wasn't properly defined or referenced,
it would generate a not defined error.

As it is the self::showPath() call had to be nested in an anonymous function. I presume that is what
the problem is

But the array property is a string, so why would that not serve the purpose?

Thanks for time and attention
JK
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
Re: [PHP] Syntax generating error?
April 02, 2017 02:40AM
On Sat, Apr 1, 2017 at 5:45 PM, Jeffry Killen <[email protected]> wrote:

> Hi;
> The following error is generated by the line marked "// << error indicated"
>
> Fatal error: Function name must be a string in dev_lab_current/lab_20/php/arrayRecursorREV-2.php
> on line 556
>
> self::$_localParams = array
> (
> 'receiver'=>array('value'=>'', 'count'=>0),
> 'type'=>'',
> 'current'=>'',
> 'value'=>'',
> 'count'=>'',
> 'len'=>'',
> 'parent'=>'',
> 'level'=>0,
> 'record'=>array(),
> 'addPath'=>function(){self::showPath();},
> 'stat'=>array()
> );
>
> print self::$_localParams['addPath']().'<br>';// << error indicated (line
> 556)
>
> This is in an early development stage and the print statement is to test
> the concept and
> the function that is supposed to be called. If the function wasn't
> properly defined or referenced,
> it would generate a not defined error.
>
> As it is the self::showPath() call had to be nested in an anonymous
> function. I presume that is what
> the problem is
>
> But the array property is a string, so why would that not serve the
> purpose?
>
> Thanks for time and attention
> JK
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
It would be the case if you are using the current stable release of PHP or
any version >= v 7.0. In older versions you will need to it in a 2-step
process:

$function = self::$_localParams['addPath'];
print $function().'<br>';
Jeffry Killen
Re: [PHP] Syntax generating error?
April 02, 2017 04:10AM
> On Apr 1, 2017, at 5:33 PM, Aziz Saleh <[email protected]> wrote:
>
>
>
> On Sat, Apr 1, 2017 at 5:45 PM, Jeffry Killen <[email protected]> wrote:
> Hi;
> The following error is generated by the line marked "// << error indicated"
>
> Fatal error: Function name must be a string in dev_lab_current/lab_20/php/arrayRecursorREV-2.php on line 556
>
> self::$_localParams = array
> (
> 'receiver'=>array('value'=>'', 'count'=>0),
> 'type'=>'',
> 'current'=>'',
> 'value'=>'',
> 'count'=>'',
> 'len'=>'',
> 'parent'=>'',
> 'level'=>0,
> 'record'=>array(),
> 'addPath'=>function(){self::showPath();},
> 'stat'=>array()
> );
>
> print self::$_localParams['addPath']().'<br>';// << error indicated (line 556)
>
> This is in an early development stage and the print statement is to test the concept and
> the function that is supposed to be called. If the function wasn't properly defined or referenced,
> it would generate a not defined error.
>
> As it is the self::showPath() call had to be nested in an anonymous function. I presume that is what
> the problem is
>
> But the array property is a string, so why would that not serve the purpose?
>
> Thanks for time and attention
> JK
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> It would be the case if you are using the current stable release of PHP or any version >= v 7.0. In older versions you will need to it in a 2-step process:
>
> $function = self::$_localParams['addPath'];
> print $function().'<br>';

Thank you for the response:

The version I am working on for development is 5.5.36 as on Mac OSX Yosemite (Apache with php module enabled);

I have developed a module in javascript that I am translating into php.

I realize there are different scoping concerns between php and javascript, and
that javascript does not have associative arrays specifically, only objects. Every
variable in javascript is directly available to scopes below it. It does not have
to be passed by reference or value.

var sample = 'help';
var test = function()
{
alert(sample)
}
test() //// produces an alert dialog: "help" in a browser.

That is not the case in php,

As I understand it, in php
$sample = 'help';
$_test = function($a)
{
print $a;
}
$_test($sample) // prints "help"

So I am going to have to struggle a bit to shake this one out.
One of my main aims is to be able to recurse over multidimensional arrays and supply
a user defined function with a record of the progress: so, the self:$_localParams array.
The addPath element will be available to the user defined function to produce the branch
of the array that a search parameter is looking for. So It will be called in much the same
way as in my original code sample.

Thank you for time and attention
JK


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Sorry, only registered users may post in this forum.

Click here to login