Passing by Reference in PHP 5.x -


I'm studying for Zend PHP5 authentication, everything looks okay, but I'm going to go through the actual Examples of the world have not been found.

It would be great if someone used to use an example?

Suppose that you want to type a function that draws some values ​​from the array.

Remove the
  function _elements ($ array, $ item1, $ item2, ...) {...}  

You can copy the array And can return it. But what if you want to know that anything was removed? Instead you can modify the in-place array and return the number of deleted elements. Therefore:

Remove function _elements (& amp; $ arrays) {// Remove element returned $ number_removed; }

If you create a complex structure inside your functions, then you may want to return a reference instead of a copy of it. But this is a very minor matter because PHP uses per-on-write (i.e. it has been copied until it has been modified) but there are some valid usage cases in it.

While returning by context, you write more about the work of a member of a class, you can return the context of any data member but it can also break the encapsulation.

Finally, it is worth noting that all the objects are passed and come back by reference by default. Everything else is passed and returned by value.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -