0

How construct is working here in my script?

If I am not using function __construct() then my script is giving output using function Cat(). What is the right way to use Construct?

  class Cat
  {
    function Cat1()
     {
       echo 'wow-wow';
     }
    function Cat()
     {
       echo 'meow';
     }  
    function __construct()
     {
    echo 'meow'."</br>";
echo 'You are reading this because I am in</br>$billi my mind came from class cat which is using</br> function __construct(). That was my origin ';
     }
  }
  $billi= new Cat();
BiscuitBaker
  • 1,421
  • 3
  • 23
  • 37
user3292058
  • 61
  • 1
  • 8
  • *'For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, it will search for the old-style constructor function, by the name of the class.'* -- http://stackoverflow.com/a/6872939/1612146 – George Mar 06 '14 at 12:53

1 Answers1

2

Because in this case, when you have a method Cat, it's a constructor.

PHP recognizes when you have a method which is exactly same the class name as a constructor.

Andrey
  • 1,476
  • 1
  • 11
  • 17