PHP cannot find the class?

Source: Internet
Author: User
{Code...} Why is an error reported? Fatalerror: Class & #039; testString & #039; notfound. If I remove extendsFather, the output will be normal.
    
  test1());    class testString extends Father{        public function test1(){            return 1;        }    }

  

Why is an error reported?

Fatal error: Class 'testString' not found

If I removeextends FatherThen the output is normal.

Reply content:
    
   test1());    class testString extends Father{        public function test1(){            return 1;        }    }

   

Why is an error reported?

Fatal error: Class 'testString' not found

If I removeextends FatherThen the output is normal.

First, from the code you posted, you should write it in two files. There is no require or include Father class file in the testString class file.
Second, it is also the key to your problem. The sequence of class declaration. During file compilation, when the testString class declaration is compiled, no Father class is found (that is, not declared ), in this case, the testString class Declaration fails. You can use class_exists () to verify it. Therefore, when the testString class is instantiated, the error "class 'teststring' not found" is returned.

Declare the parent class before it inherits its subclass.

Because your definition is behind the call.

Definitely wrong.

Sequential execution,testStringYou have not defined it.new.

Write the parent class before the subclass. instantiate the class after it is defined.

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.