Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are php5 function parameters passed as references or as copies?

Are Php function parameters passed as references to object or as copy of object?

It's very clear in C++ but in Php5 I don't know.

Example:

<?php
$dom = new MyDocumentHTMLDom();
myFun($dom);

Is parameter $dom passed as a reference or as a copy?

like image 672
Ben Avatar asked Dec 16 '22 23:12

Ben


1 Answers

In PHP5, objects are passed by reference. Well, not exactly in technical way, because it's a copy - but object variables in PHP5 are storing object IDENTIFIER, not the object itself, so essentially it's the same as passing by reference.

More here: http://www.php.net/manual/en/language.oop5.references.php

like image 52
Tomasz Struczyński Avatar answered Jan 17 '23 15:01

Tomasz Struczyński