S
S
sddvxd2017-02-26 12:57:04
PHP
sddvxd, 2017-02-26 12:57:04

What will be the value of the variable?

Good afternoon again!

$x = 9;
      $y = $x;
      $x = 5;

At the output I get that x = 5, y = 9 The question
is, why not x = 5, y = 5, because we pass a reference to the storage address of x

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
McBernar, 2017-02-26
@sddvxd

No no. This is a value assignment.
To assign a link, you need to write $y = &$x;

T
ThunderCat, 2017-02-26
@ThunderCat

In php, variables of a simple type are passed by value, the prefix & is used to pass a reference to a variable, starting from php5 objects are passed by reference, before that objects were also passed by value (cloned), now there is a separate clone() function for cloning an object;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question