Professional Web Applications Themes

#39664 [NEW]: Invokation of non-static method as static issue - PHP Bugs

From: john dot hargrove at sellingsource dot com Operating system: Gentoo Linux 2.6 kernel PHP version: 5.2.0 PHP Bug Type: Scripting Engine problem Bug description: Invokation of non-static method as static issue Description: ------------ PHP5 allows you to invoke a non-static method as static if you have E_STRICT disabled through the Class::Method() syntax which is intended functionality. I believe this bug may actually be a throwback to PHP4 functionality, but it results in funky error reporting in PHP5. If you make a static call to a non-static method, from an instance of another class, the $this variable is in scope ...

  1. #1

    Default #39664 [NEW]: Invokation of non-static method as static issue

    From: john dot hargrove at sellingsource dot com
    Operating system: Gentoo Linux 2.6 kernel
    PHP version: 5.2.0
    PHP Bug Type: Scripting Engine problem
    Bug description: Invokation of non-static method as static issue

    Description:
    ------------
    PHP5 allows you to invoke a non-static method as static if you have
    E_STRICT disabled through the Class::Method() syntax which is intended
    functionality. I believe this bug may actually be a throwback to PHP4
    functionality, but it results in funky error reporting in PHP5. If you
    make a static call to a non-static method, from an instance of another
    class, the $this variable is in scope from the calling instance. This
    breaks visibility and scope rules. Note that I saw all the PHP4 bug
    reports for this marked as bogus for reasons that made sense, but did not
    see a PHP5 bug marked similarly. The only reason I can see for this is
    compatibility?

    Also of note is that the method is aware of being out of the context of an
    object if called from the global scope. This only occurs from the context
    of an object (which makes sense).



    Reproduce code:
    ---------------
    <?php
    class A
    {
    private $private_var;

    public function Tester()
    {
    echo $this->private_var;
    }
    }
    class B
    {
    public function TesterBlah()
    {
    A::Tester();
    }
    }

    $b = new B();
    $b->TesterBlah();
    ?>


    Expected result:
    ----------------
    Fatal error: Using $this when not in object context in /root/bug/test.php
    on line 8

    Actual result:
    --------------
    Notice: Undefined property: B::$private_var in /root/bug/test.php on line
    8


    --
    Edit bug report at [url]http://bugs.php.net/?id=39664&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=39664&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=39664&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=39664&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=39664&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=39664&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=39664&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=39664&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=39664&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=39664&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=39664&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=39664&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=39664&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=39664&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=39664&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=39664&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=39664&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=39664&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=39664&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=39664&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=39664&r=mysqlcfg[/url]
    john dot hargrove at sellingsource dot com Guest

  2. #2

    Default #39664 [Opn->Bgs]: Invokation of non-static method as static issue

    ID: 39664
    Updated by: [email]tony2001php.net[/email]
    Reported By: john dot hargrove at sellingsource dot com
    -Status: Open
    +Status: Bogus
    Bug Type: Scripting Engine problem
    Operating System: Gentoo Linux 2.6 kernel
    PHP Version: 5.2.0
    New Comment:

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the doentation available at
    [url]http://www.php.net/manual/[/url] and the instructions on how to report
    a bug at [url]http://bugs.php.net/how-to-report.php[/url]




    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-28 19:03:04] john dot hargrove at sellingsource dot com

    Description:
    ------------
    PHP5 allows you to invoke a non-static method as static if you have
    E_STRICT disabled through the Class::Method() syntax which is intended
    functionality. I believe this bug may actually be a throwback to PHP4
    functionality, but it results in funky error reporting in PHP5. If you
    make a static call to a non-static method, from an instance of another
    class, the $this variable is in scope from the calling instance. This
    breaks visibility and scope rules. Note that I saw all the PHP4 bug
    reports for this marked as bogus for reasons that made sense, but did
    not see a PHP5 bug marked similarly. The only reason I can see for
    this is compatibility?

    Also of note is that the method is aware of being out of the context of
    an object if called from the global scope. This only occurs from the
    context of an object (which makes sense).



    Reproduce code:
    ---------------
    <?php
    class A
    {
    private $private_var;

    public function Tester()
    {
    echo $this->private_var;
    }
    }
    class B
    {
    public function TesterBlah()
    {
    A::Tester();
    }
    }

    $b = new B();
    $b->TesterBlah();
    ?>


    Expected result:
    ----------------
    Fatal error: Using $this when not in object context in
    /root/bug/test.php on line 8

    Actual result:
    --------------
    Notice: Undefined property: B::$private_var in /root/bug/test.php on
    line 8



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39664&edit=1[/url]
    tony2001@php.net Guest

  3. #3

    Default #39664 [Bgs]: Invokation of non-static method as static issue

    ID: 39664
    User updated by: john dot hargrove at sellingsource dot com
    Reported By: john dot hargrove at sellingsource dot com
    Status: Bogus
    Bug Type: Scripting Engine problem
    Operating System: Gentoo Linux 2.6 kernel
    PHP Version: 5.2.0
    New Comment:

    Given that this has been around since PHP4, and the manual not being
    especially clear about it, and there not really having been a clear
    answer as to why this is considered intended functionality. Is it
    right to say that this is a side effect of static method calls being
    resolved at compile time, and not necessarily so much intended as it is
    a very difficult to fix side effect? I'm not trying to stir the pot, I
    just want to make sure we're on the same page as far as this being
    Bogus, as well as anyone else who reads this bug report.


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-28 19:13:57] [email]tony2001php.net[/email]

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the doentation available at
    [url]http://www.php.net/manual/[/url] and the instructions on how to report
    a bug at [url]http://bugs.php.net/how-to-report.php[/url]



    ------------------------------------------------------------------------

    [2006-11-28 19:03:04] john dot hargrove at sellingsource dot com

    Description:
    ------------
    PHP5 allows you to invoke a non-static method as static if you have
    E_STRICT disabled through the Class::Method() syntax which is intended
    functionality. I believe this bug may actually be a throwback to PHP4
    functionality, but it results in funky error reporting in PHP5. If you
    make a static call to a non-static method, from an instance of another
    class, the $this variable is in scope from the calling instance. This
    breaks visibility and scope rules. Note that I saw all the PHP4 bug
    reports for this marked as bogus for reasons that made sense, but did
    not see a PHP5 bug marked similarly. The only reason I can see for
    this is compatibility?

    Also of note is that the method is aware of being out of the context of
    an object if called from the global scope. This only occurs from the
    context of an object (which makes sense).



    Reproduce code:
    ---------------
    <?php
    class A
    {
    private $private_var;

    public function Tester()
    {
    echo $this->private_var;
    }
    }
    class B
    {
    public function TesterBlah()
    {
    A::Tester();
    }
    }

    $b = new B();
    $b->TesterBlah();
    ?>


    Expected result:
    ----------------
    Fatal error: Using $this when not in object context in
    /root/bug/test.php on line 8

    Actual result:
    --------------
    Notice: Undefined property: B::$private_var in /root/bug/test.php on
    line 8



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39664&edit=1[/url]
    john dot hargrove at sellingsource dot com Guest

  4. #4

    Default #39664 [Bgs]: Invokation of non-static method as static issue

    ID: 39664
    Updated by: [email]tony2001php.net[/email]
    Reported By: john dot hargrove at sellingsource dot com
    Status: Bogus
    Bug Type: Scripting Engine problem
    Operating System: Gentoo Linux 2.6 kernel
    PHP Version: 5.2.0
    New Comment:

    Yes, it's some kind of a left-over of PHP4, but it is necessary to keep
    BC with the code written with PHP4 in mind.
    I guess we can/will change it in PHP6, but in 5.x it should remain as
    it is.


    Previous Comments:
    ------------------------------------------------------------------------

    [2006-11-28 22:23:53] john dot hargrove at sellingsource dot com

    Given that this has been around since PHP4, and the manual not being
    especially clear about it, and there not really having been a clear
    answer as to why this is considered intended functionality. Is it
    right to say that this is a side effect of static method calls being
    resolved at compile time, and not necessarily so much intended as it is
    a very difficult to fix side effect? I'm not trying to stir the pot, I
    just want to make sure we're on the same page as far as this being
    Bogus, as well as anyone else who reads this bug report.

    ------------------------------------------------------------------------

    [2006-11-28 19:13:57] [email]tony2001php.net[/email]

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the doentation available at
    [url]http://www.php.net/manual/[/url] and the instructions on how to report
    a bug at [url]http://bugs.php.net/how-to-report.php[/url]



    ------------------------------------------------------------------------

    [2006-11-28 19:03:04] john dot hargrove at sellingsource dot com

    Description:
    ------------
    PHP5 allows you to invoke a non-static method as static if you have
    E_STRICT disabled through the Class::Method() syntax which is intended
    functionality. I believe this bug may actually be a throwback to PHP4
    functionality, but it results in funky error reporting in PHP5. If you
    make a static call to a non-static method, from an instance of another
    class, the $this variable is in scope from the calling instance. This
    breaks visibility and scope rules. Note that I saw all the PHP4 bug
    reports for this marked as bogus for reasons that made sense, but did
    not see a PHP5 bug marked similarly. The only reason I can see for
    this is compatibility?

    Also of note is that the method is aware of being out of the context of
    an object if called from the global scope. This only occurs from the
    context of an object (which makes sense).



    Reproduce code:
    ---------------
    <?php
    class A
    {
    private $private_var;

    public function Tester()
    {
    echo $this->private_var;
    }
    }
    class B
    {
    public function TesterBlah()
    {
    A::Tester();
    }
    }

    $b = new B();
    $b->TesterBlah();
    ?>


    Expected result:
    ----------------
    Fatal error: Using $this when not in object context in
    /root/bug/test.php on line 8

    Actual result:
    --------------
    Notice: Undefined property: B::$private_var in /root/bug/test.php on
    line 8



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39664&edit=1[/url]
    tony2001@php.net Guest

Similar Threads

  1. Static variable/method
    By eztaburnak in forum Macromedia Flex General Discussion
    Replies: 8
    Last Post: May 20th, 06:37 AM
  2. Replies: 2
    Last Post: December 3rd, 12:47 AM
  3. Replies: 3
    Last Post: October 5th, 03:04 PM
  4. Replies: 1
    Last Post: September 11th, 09:21 PM
  5. static method and $this
    By Messju Mohr in forum PHP Development
    Replies: 0
    Last Post: August 7th, 08:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139