thinkphp icon indicating copy to clipboard operation
thinkphp copied to clipboard

NULL returns when in_array function with global static variable!

Open yasar-luo opened this issue 9 years ago • 1 comments

Hello, I found out a mistake which is when using php funciton "in_array" to search the global static variable! It like this: First, define a array:

`$example_array = array('Index' => 'index');`

Then:

$status = in_array(ACTION_NAME, $example_array[CONTROLLER_NAME]);

Whatever the action is index or not when the controller is Index, it always returns NULL(the $status). I tried another way to solve it:

$action = ACTION_NAME;

$actions = $example_array[CONTROLLER_NAME];

$status = in_array($action, $actions);

This method will return NULL or bool(true) correctly.

yasar-luo avatar Dec 24 '16 08:12 yasar-luo

the usecase of in_array() is "bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] )"

you used it in the wrong way 。because the second parameter needs to be array not string,however you set it with a string

hainuo avatar Jan 01 '17 12:01 hainuo