Welcome, Guest
Username: Password: Remember me

TOPIC: Pass by reference needed

Pass by reference needed 15 Jun 2016 06:06 #14066

  • vlemos
  • vlemos's Avatar
  • Online
  • Elite Member
  • Posts: 295
  • Thank you received: 41
  • Karma: 21
$item was passed in by reference; should it not be passed by reference here as well?
public function populateObjects(&$item)
	{
		if (!empty($item->params) && is_string($item->params))
		{
			$registry = new JRegistry;
			$registry->loadString($item->params);
			$item->params = $registry->toObject();
		}
	
		parent::populateObjects($item);
	}
parent::populateObjects(&$item);
The administrator has disabled public write access.

Pass by reference needed 15 Jun 2016 08:20 #14069

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
If you do that, PHP5 will throw a big error.

No, it is deprecated and finished this this when you use the '&' in the call. Only for arrays, and only for declarations of the parameters of the function.
All objects are pointer, so only simple vars and arrays need that. but only in the parameters declaration.

Even here in our case, I am not sure if it is required in the declaration. It is just a coding style for the coder to remember it is a OUTPUT parameter.
But when $item is an object, you can be sure it will be working even without '&' because it is systematically a pointer.
Coding is now a piece of cake
Last Edit: 15 Jun 2016 08:21 by admin.
The administrator has disabled public write access.
The following user(s) said Thank You: vlemos
Time to create page: 0.061 seconds

Get Started