Cloning an array of objects

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

And I guess now we know the reason for
ole wrote:If they can make it so it triggers an error when you use clone on a array then they could have it return the array with cloned objects. I personally feel its a hole in the functionality of the language.
The developers of php simply saw no need for cloning arrays ;)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

ole wrote:

Code: Select all

/**
 * Recursively iterates over an array cloning any objects encountered
 *
 * @param array $toClone
 * @return array
 */
static public function arrayRecursiveClone(array $toClone)
{
Psst... you have "static" in the wrong place ;)

EDIT |
Manual wrote:The static declaration must be after the visibility declaration. For compatibility with PHP 4, if no visibility declaration is used, then the member or method will be treated as if it was declared as public.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

d11wtq wrote:Psst... you have "static" in the wrong place ;)

EDIT |
Manual wrote:The static declaration must be after the visibility declaration. For compatibility with PHP 4, if no visibility declaration is used, then the member or method will be treated as if it was declared as public.
PHP 4, PHP snore. I don't care about that. :lol:
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

It's two separate sentences. You should still have static second. It's the same in Java.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Oh right then its quite possible neither php 4 or 5 cares given this example.
Post Reply