Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Warning: array_merge(): Argument #1 is not an array in include/classes/scrambler.php on line 255 #79

Open
sedimentation-fault opened this issue Jul 6, 2020 · 0 comments

Comments

@sedimentation-fault
Copy link

I get

PHP Warning:  array_merge(): Argument #1 is not an array in include/classes/scrambler.php on line 
255

The line in question contains

$this->t_ignore_prefix = array_merge($this->t_ignore_prefix,$t);

so $this->t_ignore_prefix is not an array at the time array_merge() is called, not even an empty one.

I know this is just a warning and not an error, but reading the docs on array_merge, I see, among others, this comment:

$a = array(1,2,3); // an array
$b = 5; // anything but not an array

$c = array_merge($a, $b); // shows a PHP warning: Argument #2 is not an array

var_dump($c); // output as NULL

// now merge in reverse order
$d = array_merge($b, $a); // shows a PHP warning: Argument #1 is not an array

var_dump($d); // output as NULL

NOTE: For any operation that relies on the previous array merge operation it is highly necessary to check the arguments as well as the result of the merge are arrays before continuing as the warning would not stop the operation and this might result in data loss and what not... and this should also be stated in the .documentation. Example #3 somewhat started to demonstrate this but used type casting which made this irrelevant to this matter.

You may say, "in our case the result of merging the non-array $this->t_ignore_prefix with $t will still be OK", but relying on such effects is very obscure behavior to me.

Solution

Initialize all arrays to the empty array:

In the constructor of scrambler, at the top, where other $this properties are initialized, add:

        $this->t_ignore_prefix      = array();
        $this->t_ignore             = array();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant