Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

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

  • vlemos
  • vlemos's Avatar Topic Author
  • Offline
  • Elite Member
  • Elite Member
  • Posts: 295
  • Thank you received: 41
$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);

Please Log in or Create an account to join the conversation.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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
The following user(s) said Thank You: vlemos

Please Log in or Create an account to join the conversation.

Last edit: by admin.
  • Page:
  • 1
Time to create page: 0.232 seconds

Although I found this tool some time ago I just started learning experimenting and building this first component on Monday and now on Thursday afternoon it's already online. Although I already had a working version done with another tool this is much easier to build and at the end you have the freedom to own your own component. Once you know how to use Cook you will boost your productivity as the learning curve is really moderate compared to many other tools.
Giori (Forum)

Get Started