Sunday, May 5, 2013

In php5, If a class has both __construct() and class name as function, which will be called while creating objects ?

Answer: Only __construct() will be called.

Try out example

<?php

class myClass
{

    function myClass()
    {
        echo "In class name";
    }

    function __construct()
    {
        echo "In __construct";
    }
}
$obj = new myClass();
?>

Output: In __construct


No comments:

Post a Comment