Are PHP5 objects passed by reference?

后端 未结 8 791
抹茶落季
抹茶落季 2020-11-27 03:45

I can\'t seem to get any consistent info on this. Different sources appear to say different things and the venerable php.net itself (appears) not to explicitly stat

8条回答
  •  醉话见心
    2020-11-27 04:41

    Yes from PHP5 onwards, objects are passed by reference. No need to do that explicitly.

    http://www.php.net/manual/en/migration5.oop.php

    In PHP 5 there is a new Object Model. PHP's handling of objects has been completely rewritten, allowing for better performance and more features. In previous versions of PHP, objects were handled like primitive types (for instance integers and strings). The drawback of this method was that semantically the whole object was copied when a variable was assigned, or passed as a parameter to a method. In the new approach, objects are referenced by handle, and not by value (one can think of a handle as an object's identifier).

提交回复
热议问题