php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66648 problem with the definition of a method
Submitted: 2014-02-05 17:22 UTC Modified: 2014-02-05 20:55 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: Viktorlubchuk at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.5.8 OS: linux mint 16
Private report: No CVE-ID: None
 [2014-02-05 17:22 UTC] Viktorlubchuk at gmail dot com
Description:
------------
the is bug is that I appeal to the public methods as static and it works

i try it on php versions 5.4 , 5.3 and its outputting error as it should be






<?php
  
namespace PHP_SINGLETONE;


abstract class Example
{

    public static $counter = null;
    protected $num;
    public function __construct()
    {

    }

    public function in()
    {
        $class = get_called_class();
        if ($class::$counter === null) {

            $class::$counter =  new $class();
        }

        return $class::$counter;

    }

    public function doSome($string)
    {
        echo get_called_class(). " ".$string."<br>";
    }

    public function showNum($number)
    {
        $this->num = $number;

        return $this->num;

    }


}


class Example1 extends Example
{
    public static $counter = null;

}



class Example2 extends Example
{
    public static $counter = null;
    
}

$var = Example1::in();

$var::doSome('var1');

$var1 = Example2::in();

$var1::doSome('var2');
var_dump($a = $var1->showNum("6"));

echo $a;


Expected result:
----------------
i`m expecting to error that say - I can not appeal to the public methods as static


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-05 19:47 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: Compile Failure +Package: Scripting Engine problem
 [2014-02-05 19:47 UTC] requinix@php.net
You can call a non-static method statically - PHP allows that (for the time being) - but it will issue an E_STRICT. If you don't see the message then you don't have your error_reporting and/or display_errors settings set to show it.


Strict Standards: Non-static method PHP_SINGLETONE\Example::in() should not be called statically in ... on line 58

Strict Standards: Non-static method PHP_SINGLETONE\Example::doSome() should not be called statically in ... on line 60
PHP_SINGLETONE\Example1 var1<br>
Strict Standards: Non-static method PHP_SINGLETONE\Example::in() should not be called statically in ... on line 62

Strict Standards: Non-static method PHP_SINGLETONE\Example::doSome() should not be called statically in ... on line 64
PHP_SINGLETONE\Example2 var2<br>string(1) "6"
6
 [2014-02-05 20:55 UTC] Viktorlubchuk at gmail dot com
problem solved. thank you.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 11:00:02 2026 UTC