PHP Classes

public static function type($input) issue

Recommend this page to a friend!

      dump_r  >  All threads  >  public static function type($input)...  >  (Un) Subscribe thread alerts  
Subject:public static function type($input)...
Summary:Detecting strings such as System or exec not working
Messages:4
Author:Padraig Doran
Date:2012-10-19 17:02:39
Update:2012-10-20 01:12:09
 

  1. public static function type($input)...   Reply   Report abuse  
Picture of Padraig Doran Padraig Doran - 2012-10-19 17:02:39
In the "public static function type($input)" function, at the section that is commented "// avoid detecting strings with names of global functions as callbacks", the function doesn't see to filter out the strings correctly.

For example, if I have

$obj->name = 'System';

and I do a print_r($obj) I get

[name] => System

but if I use dump_r($obj) I get

name fn()

The above is incorrect as I want the text 'System' to be displayed, not "fn()".

If I change the condition to

if (is_callable($input) && !(is_string($input)) && function_exists($input))

then the word 'System' will appear which is correct but I'm not sure if it'll kill the real system() fn() usage.

  2. Re: public static function type($input)...   Reply   Report abuse  
Picture of Padraig Doran Padraig Doran - 2012-10-19 17:25:30 - In reply to message 1 from Padraig Doran
having

if (is_callable($input) && !(is_string($input) || function_exists($input)))

give the following

example.php results:

call_anon fn()
call_static lib::myFn 9
call_array fn()

my test:
name System 6

  3. Re: public static function type($input)...   Reply   Report abuse  
Picture of Leon Sorokin Leon Sorokin - 2012-10-19 22:25:06 - In reply to message 2 from Padraig Doran
interesting, i'm not seeing this happen here.

i've added $obj->syst = 'System'; into the example.php file and it dumps the string correctly.

you can see it here: http://o-0.me/dump_r/

the original logic looks okay to me, i wonder if it's a php version difference. i'm testing on 5.4.7 actually. what are you running?

  4. Re: public static function type($input)...   Reply   Report abuse  
Picture of Leon Sorokin Leon Sorokin - 2012-10-20 01:12:09 - In reply to message 2 from Padraig Doran
slightly related - i've updated the lib to display additional details about detected callbacks. this change should not affect the issue you're describing though.