brijesh
Are objects passed by value or by reference?
1 Answer(s)      4 years and 10 months ago
Posted in : PHP

Are objects passed by value or by reference?

Advertisement
View Answers

November 15, 2010 at 1:24 PM


Hi everyone,

Everything is passed by value.

Example :

<?php
    function fruitName($name = "apple")
    {
     return "Fruit is $name.";
    }
    echo fruitName();
    echo "<br>";
    echo fruitName(null);
    echo "<br>";
    echo fruitName("Strawberry");
 ?>

Output :

Fruit is apple.
Fruit is .
Fruit is Strawberry.

Thanks