gpt4 book ai didi

php - 这是一个PHP错误吗? (关于延伸)

转载 作者:可可西里 更新时间:2023-11-01 00:26:06 27 4
gpt4 key购买 nike

class A extends B {}
class B extends C{}
class C {}

结果

PHP Fatal error: class 'B' not found ...

如果顺序是这样

class A extends B {}
class C {}
class B extends C{}

一切正常


PS:如果我删除 C 类{}

class A extends B {}
class B extends C{}

php 告诉我找不到类 'B',为什么?

php 版本 5.3.4

最佳答案

PHP manual明确提到:

Classes must be defined before they are used! If you want the class Named_Cart to extend the class Cart, you will have to define the class Cart first. If you want to create another class called Yellow_named_cart based on the class Named_Cart you have to define Named_Cart first. To make it short: the order in which the classes are defined is important.

关于php - 这是一个PHP错误吗? (关于延伸),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6355302/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com