Home > Backend Development > PHP Tutorial > 为什么第一种情况是正确的呢,不是说,继承父类需要放在子类之前吗?(PHP)

为什么第一种情况是正确的呢,不是说,继承父类需要放在子类之前吗?(PHP)

WBOY
Release: 2016-06-06 20:21:48
Original
1068 people have browsed it

1、正常情况

<code>class A extends B {}

class C {}

class B extends C {}
</code>
Copy after login
Copy after login

2、错误

<code>class A extends B {}

class B extends C {}

class C {}
</code>
Copy after login
Copy after login

Fatal error: Class 'B' not found

回复内容:

1、正常情况

<code>class A extends B {}

class C {}

class B extends C {}
</code>
Copy after login
Copy after login

2、错误

<code>class A extends B {}

class B extends C {}

class C {}
</code>
Copy after login
Copy after login

Fatal error: Class 'B' not found

类只有在定义后才可以使用!如果需要类 Named_Cart 继承类 Cart,必须首先定义 Cart 类。如果需要创建另一个基于 Named_Cart 类的 Yellow_named_cart 类,必须首先定义 Named_Cart 类。简捷的说:类定义的顺序是非常重要的。《php手册》

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template