php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68872 all
Submitted: 2015-01-21 09:55 UTC Modified: 2015-01-21 10:20 UTC
From: mlboy at 126 dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.6.4 OS: centos7
Private report: No CVE-ID: None
 [2015-01-21 09:55 UTC] mlboy at 126 dot com
Description:
------------
---
From manual page: http://www.php.net/language.oop5
---
when call a static funciton name with a same as class name will get this error.


  1 <?php
  2 class A{
  3     static public function A(){
  4         echo 'hi';
  5     }
  6 }
  7 A::A();
Fatal error: Constructor A::A() cannot be static in /t.php on line 6


Test script:
---------------
<?php
class A{
    static public function A(){
      echo 'hi';
    }
}
A::A();



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-01-21 10:16 UTC] spam dot remy at hotmail dot com
That is correct behaviour. From http://php.net/manual/en/language.oop5.decon.php :
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.
 [2015-01-21 10:20 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-01-21 10:20 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 13:01:30 2024 UTC