NYCPHP Meetup

NYPHP.org

[nycphp-talk] Minor rant, pass by reference during method invocation depreciated

Rob Marscher rmarscher at beaffinitive.com
Fri Jul 2 11:25:31 EDT 2010


On Jul 2, 2010, at 10:58 AM, John Campbell wrote:
>> $grantUser object updated with the new levels or not. If I know I am dealing
>> with the current user, than I want the admin authority to immediately be
>> applied so it will flow to all future function calls:
>> $return= Application::setUserRole(&$grantUser, USER_ADMIN);
>> Wheras if I am dealing with the previous user, I may very well want to keep
>> the original user to see if any changes where made:
>> $return = Application::setUserRole($grantUser, USER_ADMIN);
> 
> Objects are always passed by reference.  You don't have a choice.
> What is the point of this rant?  Passing strings / ints by reference
> is a pointless feature of php.

Yeah, use the "clone" keyword to clone an object if you don't want changes to it to be propegated to all the other references.  http://php.net/manual/en/language.oop5.cloning.php





More information about the talk mailing list