PHP can call non-static methods in static form.

Source: Internet
Author: User
PHP can call non-static methods in static form. This post was last edited by lytreo650 in 2014-03-1410: 05: 21 & lt ;? Phpclass & nbsp; test & nbsp; {public & nbsp; function & nbsp; sayHello & nbsp; () & nbsp; {echo PHP can call non-static methods in static form.

This post was last edited by lytreo650 at 10:05:21

 Class test {
Public function sayHello (){
Echo 'hello world ';
}
}
Test: sayHello ();


Run the above code to print out hello world without any error.
However, I read the book "in-depth PHP object-oriented, patterns and practices", which clearly states
A non-static method can be called statically only when the parent keyword is used to call a method.


What is going on here? It is hard to say that PHP does not support this in mind, but it can actually do this?
------ Solution --------------------
It is the practice of php to call a non-static method in the static form.
Only the E_STRICT check is introduced in php 5.3, and php 5.4 enforces the check.
------ Solution --------------------
It is related to the error check level of different php versions.
------ Solution --------------------
That's of course!
You do not have ~ E_STRICT?
Error checks at the E_STRICT level are blocked.

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.