Why does the following code print out 10 instead of null?

oop, php

Solution

Because `public function a()` is a constructor.

For backwards compatibility, if PHP 5 cannot find a __construct() function for a given class, and the class did not inherit one from a parent class, it will search for the old-style constructor function, by the name of the class.

see more at PHP constructor manual

Problem

The following code outputs `10`. Why is that? ``` <?php class a{ var $c; public function a(){ $this->c=10; } } class b extends a{ public function print_a(){ print $this->c; } } $b=new b; $b->print_a(); ```

Original source