Reputation: 19762
Are strings referenced or copied, when passed as arguments or assigned to variables, in PHP5?
Upvotes: 3
Views: 78
Reputation: 401142
The debug_zval_dump()
function might help you answer this question.
$str = 'test';
debug_zval_dump($str); // string(4) "test" refcount(2)
my_function($str);
debug_zval_dump($str); // string(4) "test" refcount(2)
function my_function($a) {
debug_zval_dump($a); // string(4) "test" refcount(4)
$plop = $a . 'glop';
debug_zval_dump($a); // string(4) "test" refcount(4)
$a = 'boom';
debug_zval_dump($a); // string(4) "boom" refcount(2)
}
I get the following output :
string(4) "test" refcount(2)
string(4) "test" refcount(4)
string(4) "test" refcount(4)
string(4) "boom" refcount(2)
string(4) "test" refcount(2)
Upvotes: 7