PHP Constructor Curiosity

With the development of my own MVC framework I stumbled over a weird PHP problem which only really matters for just-PHP-programmers. Since in PHP 5.3.0 a constructor can be declared as a method named after the class.

<?php
class Index {
  public function __construct() { echo "before 5.3.0"; }
  public function index() { echo "5.3.0 or later"; }
  // case of function name doesn't matter!
}

$blub = new Index();

Inside namespaces this “feature” was removed with PHP version 5.3.3. Outside of namespaces it still exists.

Personally I am not happy about this change, since it is not consistent with PHP destructor functions.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>