Why a member method in a DB class in PHP can be used as a static method! Asking for advice?

Source: Internet
Author: User
PHP Class object

This is a db.php file, inside is a DB class
Class db{    function &object ()    {        static $db;        if (empty ($db))        {            $db = new Pgsql ();        }        return $db;    }    function query ($sql, $transaction = False)    {        $db = & Db::object ();                Return $db->query ($sql, $transaction);    }}


My question is that the methods in the DB class are not static (static), why it can be used in an external PHP file like Db::query (), and Db::object (), which is used internally by himself, I wonder why? is not a static method to use it??

Ask the great God pointing twos!! Thank you here first!


Reply to discussion (solution)

This is PHP4 code.
PhP4 don't have that much restraint.

This is PHP4 code.
PhP4 don't have that much restraint.

This is PHP4 code.
PhP4 don't have that much restraint.

This is PHP4 code.
PhP4 don't have that much restraint.

My PHP environment is more than 5.2, it is also support PHP4 code??

PHP5 can be conditionally accepted PHP4.

PHP 5.2 is basically consistent with PHP4, except that objects are always passed by reference, without the use of claims &
Non-static methods cannot be used statically when PHP 5.3 turns on e_strict level error checking
PHP 5.4 Turns on e_strict level error checking by default and cannot statically use non-static methods

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.