Re: Re: Function variables in classes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/1/07, Jochem Maas <jochem@xxxxxxxxxxxxx> wrote:
>
> Sebastian Hopfe wrote:
> > I think you should log it, because it seems to be, and you found this
> > error.
>
> it's not a bug - especially because nobody has bothered to mention the php
> version.


this issue has the same implications in php4 and php5, because its about
variable functions
and phps inability to resolve class names or references from the contents of
a variable
when the variable is used in the context of a class method invocation.

I'm guessing that it's being run on a version php5, in which case the fatal
> error
> seems correct - you have a non-static method defined and then you are
> trying to
> call that method statically which is not allowed (IIRC whether this works
> or not
> depends on the minor version of php5 your running - something the
> OO-purism gang
> forced on us, actually the restriction may have been removed again - I've
> completely
> lost track of the state of the exact OO rules in any given version of
> php5)


i dont know what the version granularity is either regarding the use of
static class methods
being invoked when the methods are not declared static.  i dont think ive
ever seen a fatal
error raised for that, and at any rate, the error clearly indicates that it
pertains to the misuse
of static method, in that case, which is not the case in the error message
reported earlier.

Error raised when invoking a method not defined as static from a static
context:
(5.2.4-pl2-gentoo)
Strict standards: Non-static method Foo::nonStaticMethod() should not be
called statically in
/home/nathan/workspace/sacd/svn/itc-dev/testStaticCall2.php on line 14

(original error message from this thread)
Fatal error: Call to undefined function foobar::bar2() in
/home/paul/demo/demo.php on line 25

this strengthens the case that i made earlier, namely this issue is a result
of phps lack of
resolving class names and references when they are embedded in a string that
is used as
a variable function.

here is a code fragment to test the static method calls out against any
version of php5.

<?php
class Foo {
    static public function staticMethod() {
        echo __METHOD__ . PHP_EOL;
    }

    public function nonStaticMethod() {
        echo __METHOD__ . PHP_EOL;
    }
}

Foo::staticMethod();
Foo::nonstaticMethod();
$foo = new Foo();
$foo->staticMethod();
$foo->nonstaticMethod();
?>

on php 5.2.4 you will have to enable E_STRICT to see the warning.

error_reporting  =  E_ALL | E_STRICT

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux