1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSの参照渡しのような、値渡し。PHPの参照渡し、値渡し。

Last updated at Posted at 2019-07-28

JSの配列やobjectは参照渡しのような値渡し。
stirngやintegerは値渡し。

@shiracamus さんにコメントで教えていただきました。

正確には、JSには値渡ししかなくて、参照渡しはできないです。オブジェクトを代入した変数にはオブジェクトの参照値が保持されていて、保持している値=オブジェクトの参照値 を渡すので、あくまで値渡しなのです。

PHPは通常、値渡し。
&をつけて&$hogeとすると参照渡し。

JSが参照渡しになることを知らなくて、なんでだー、Vueのせいかとかいろいろやった挙げ句、バグの原因がこれだったので、あーとなった。

参考
JavaScript の配列やオブジェクトは参照渡しになる…バグを生む落とし穴
http://neos21.hatenablog.com/entry/2018/05/20/080000

1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?