PHP passes array by value unless you declare function signature to take reference

yep, calling the function below will not have changed the array after the call

public function addMore(array $names) {
   $names[] = 'another';
   return;
}

..you have to declare the function signature to take a reference to the array, then the array will be changed after the call


public function addMore(array &$names) {
   $names[] = 'another';
   return;
}

Objects passed can be modified without the need to declare as references in the signature as they are passed by reference by default;

Comments

Popular posts from this blog

My Reading Lists

angular js protractor e2e cheatsheet

react-select stacking order bug, z-index, layers and stacking