# Clone Operations

- Thread: https://externals.io/message/23977
- Original archive: https://news-web.php.net/php.internals/23977
- Started by Ilia Alshanetsky on 2006-06-07T13:56:44+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #23977 — Ilia Alshanetsky — 2006-06-07T13:56:44+00:00

URL: https://externals.io/message/23977#23977

When it comes to "empty" clone statements, should they be executed  
and then free the result (current behavior) or avoid clone all together.
For example when class x { function __clone() { echo "hello"; } }  
clone new x(); code is executed, should it print hello or not print  
anything at all, treating the clone operation as a NOOP?

Current behavior calls clone and then frees the result, meaning that  
"hello" is printed, but I am uncertain that this is the correct  
behavior, any comments?

Ilia Alshanetsky

---

## #23978 — Nuno Lopes — 2006-06-07T14:04:32+00:00

URL: https://externals.io/message/23977#23978 · In reply to: #23977

I think that "hello" should be printed. Even if the result of `clone()`ing 
isn't going to be used, the side-effects should always occur (at least to be 
consistence). I would bet that other languages would do the same.

Nuno

----- Original Message ----- 
> When it comes to "empty" clone statements, should they be executed  and 
> then free the result (current behavior) or avoid clone all together.
> For example when class x { function __clone() { echo "hello"; } }  clone 
> new x(); code is executed, should it print hello or not print  anything at 
> all, treating the clone operation as a NOOP?
>
> Current behavior calls clone and then frees the result, meaning that 
> "hello" is printed, but I am uncertain that this is the correct  behavior, 
> any comments?
>
> Ilia Alshanetsky

---

## #23979 — Marcus Boerger — 2006-06-07T18:52:56+00:00

URL: https://externals.io/message/23977#23979 · In reply to: #23977

Hello Ilia,

  hello should be printed. As in you cannot outsmart what some people
might do in their code. For example in C++ such stuff gets optimized
out but only as long as the compiler detects that doing so does not
result in a different bahvior. This is something you need to know
for particular stuff in c++ like the ability of some compilers that
can optimized out implicit clone on function return - but only if the
compiler would generate the clone....ok, now back to php, do we really
want to make it that complex? I think if the programmer writes clone
or it is a consequnce of something else then let the clone happen and
the rule end there.

best regards
marcus

Wednesday, June 7, 2006, 3:56:44 PM, you wrote:

> When it comes to "empty" clone statements, should they be executed  
> and then free the result (current behavior) or avoid clone all together.
> For example when class x { function __clone() { echo "hello"; } }  
> clone new x(); code is executed, should it print hello or not print  
> anything at all, treating the clone operation as a NOOP?

> Current behavior calls clone and then frees the result, meaning that  
> "hello" is printed, but I am uncertain that this is the correct  
> behavior, any comments?

> Ilia Alshanetsky




Best regards,
 Marcus

---

## #23986 — Richard Lynch — 2006-06-08T01:19:51+00:00

URL: https://externals.io/message/23977#23986 · In reply to: #23977

> When it comes to "empty" clone statements, should they be executed
> and then free the result (current behavior) or avoid clone all
> together.
> For example when class x { function __clone() { echo "hello"; } }
> clone new x(); code is executed, should it print hello or not print
> anything at all, treating the clone operation as a NOOP?
>
> Current behavior calls clone and then frees the result, meaning that
> "hello" is printed, but I am uncertain that this is the correct
> behavior, any comments?

Seems to me that if they want echo "hello"; on __clone() for
debugging, we shouldn't cripple it... [shrug]

-- 
Like Music?
http://l-i-e.com/artists.htm
