Saturday, August 31, 2013

How to write a constructor in php4 & in php5 ?

In PHP4, a constructor is a method with a name same as that of class itself. In PHP5, all constructors are named as __construct()

Thursday, August 1, 2013

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