当前位置:首页>python>Python 中魔法函数(Magic Methods)全面系统详解

Python 中魔法函数(Magic Methods)全面系统详解

  • 2026-03-24 05:05:18
Python 中魔法函数(Magic Methods)全面系统详解

Python 中的魔法函数(Magic Methods),又称殊方法(Special Methods)或双下方法(Dunder Methods,其名称以双下划线__ 开头和结尾),是一组预定义的方法名,用于让自定义类能够模拟 Python 内置类型的行为,并支持语言的核心语法(如运算符、属性访问、函数调用等)。通过实现这些方法,可以使自定义对象表现得像内置对象一样自然,从而充分利用 Python 的灵活性和一致性。

本文将全面、详细地介绍 Python 中常用的魔法函数,按功能分类讲解每个方法的用途、参数、返回值、调用时机以及实际代码示例。


1. 对象生命周期与初始化

方法
描述
__new__(cls[, ...])
创建并返回一个新实例。在 __init__ 之前调用,是真正的构造函数(通常用于不可变类型或控制实例创建)。
__init__(self[, ...])
初始化已创建的实例。在 __new__ 之后调用,负责设置对象的初始状态。
__del__(self)
析构函数,当对象被垃圾回收时调用(注意:不保证立即调用,除非明确 del 且引用计数归零)。

示例:

classSingleton:    _instance = Nonedef__new__(cls, *args, **kwargs):ifnot cls._instance:            cls._instance = super().__new__(cls)return cls._instancedef__init__(self, value):        self.value = valuea = Singleton(10)b = Singleton(20)print(a is b)  # Trueprint(a.value, b.value)                                      
20 20(因为共享同一个实例,__init__ 被每次调用覆盖)

2. 对象字符串表示

方法
描述
__repr__(self)
返回对象的“官方”字符串表示,通常应能被 eval() 重建该对象(或给出清晰信息)。由 repr() 调用,也是 print() 回退时使用。
__str__(self)
返回对象的“非正式”字符串表示,对用户友好。由 str() 和 print() 调用。未定义时回退到 __repr__
__format__(self, format_spec)
由 format() 和 f-string 调用,实现自定义格式化。
__bytes__(self)
返回对象的字节串表示,由 bytes() 调用。

示例:

classPoint:def__init__(self, x, y):        self.x = x        self.y = ydef__repr__(self):return f"Point({self.x}{self.y})"def__str__(self):return f"({self.x}{self.y})"def__format__(self, spec):if spec == 'polar':import math            r = math.hypot(self.x, self.y)            theta = math.atan2(self.y, self.x)returnf"(r={r:.2f}, θ={theta:.2f})"return str(self)p = Point(34)print(repr(p))     print(str(p))       print(f"{p:polar}"
(r=5.00, θ=0.93)
(3, 4)
Point(3, 4)

3. 比较与哈希

方法
描述
__lt__(self, other)
小于 <
__le__(self, other)
小于等于 <=
__eq__(self, other)
等于 ==
__ne__(self, other)
不等于 !=
__gt__(self, other)
大于 >
__ge__(self, other)
大于等于 >=
__hash__(self)
由 hash() 调用,返回整数哈希值。如果对象是可哈希的(如用作字典键),需要实现此方法,通常与 __eq__ 一致。

注意: 如果定义了 __eq__ 而没有定义 __hash__,则实例会变成不可哈希的。如果希望实例可变,通常不定义 __hash__ 或设为 None

示例:

classPerson:def__init__(self, name, age):        self.name = name        self.age = agedef__eq__(self, other):ifnot isinstance(other, Person):returnNotImplementedreturn self.name == other.name and self.age == other.agedef__hash__(self):return hash((self.name, self.age))def__lt__(self, other):ifnot isinstance(other, Person):returnNotImplementedreturn self.age < other.agep1 = Person("Alice"30)p2 = Person("Alice"30)p3 = Person("Bob"25)print(p1 == p2)        # Trueprint(p1 < p3)         # Falseprint(hash(p1) == hash(p2))  # True

4. 属性访问控制

方法
描述
__getattr__(self, name)
当访问的属性不存在时被调用(属性查找失败时)。
__getattribute__(self, name)
所有属性访问都会先经过此方法(除非有显式优化)。需谨慎使用,避免无限递归。
__setattr__(self, name, value)
设置属性时调用
__delattr__(self, name)
删除属性时调用
__dir__(self)
由 dir() 调用,返回属性列表

示例:

classDynamicProxy:def__init__(self, obj):        self._obj = objdef__getattr__(self, name):        print(f"Delegating {name}")return getattr(self._obj, name)def__setattr__(self, name, value):if name == "_obj":            super().__setattr__(name, value)else:            setattr(self._obj, name, value)classData:    x = 10d = Data()proxy = DynamicProxy(d)print(proxy.x)   # 输出 Delegating x 然后 10proxy.y = 20print(d.y)       # 20

5. 容器与序列模拟

方法
描述
__len__(self)
返回容器长度,由 len() 调用。
__getitem__(self, key)
支持 self[key] 索引访问
__setitem__(self, key, value)
支持 self[key] = value 赋值
__delitem__(self, key)
支持 del self[key] 删除
__contains__(self, item)
支持 item in self。未定义时使用 __iter__ 遍历查找。
__iter__(self)
返回一个迭代器,由 iter() 调用。
__next__(self)
迭代器的下一个元素,由 next() 调用(迭代器类需实现)。
__reversed__(self)
由 reversed() 调用,返回反向迭代器
__missing__(self, key)
当在字典子类中 __getitem__ 找不到键时调用(仅用于 dict 子类)。

示例(不可变序列):

classRange:def__init__(self, start, stop, step=1):        self.start = start        self.stop = stop        self.step = stepdef__len__(self):return max(0, (self.stop - self.start + self.step - 1) // self.step)def__getitem__(self, index):if index < 0:            index += len(self)if0 <= index < len(self):return self.start + index * self.stepraise IndexError("index out of range")r = Range(1102)print(len(r))        # 5print(r[2])          # 5print(5in r)        # True(因为定义了 __getitem__ 和 __len__,Python 可以自动处理迭代和成员测试)for v in r:    print(v)         # 1 3 5 7 9

6. 数值运算魔法函数

Python 允许通过魔法函数重载所有运算符。以下分类列举:

6.1 一元运算符

方法
描述
__neg__(self)
负号 -obj
__pos__(self)
正号 +obj
__abs__(self)
绝对值 abs(obj)
__invert__(self)
按位取反 ~obj
__round__(self, n)round(obj, n)
__floor__(self)math.floor(obj)
__ceil__(self)math.ceil(obj)
__trunc__(self)math.trunc(obj)

6.2 二元算术运算符

方法
描述
__add__(self, other)
加法 +
__sub__(self, other)
减法 -
__mul__(self, other)
乘法 *
__matmul__(self, other)
矩阵乘法 @(Python 3.5+)
__truediv__(self, other)
真除法 /
__floordiv__(self, other)
整除 //
__mod__(self, other)
取模 %
__divmod__(self, other)divmod(obj, other)
__pow__(self, other[, modulo])
幂 ** 或 pow()
__lshift__(self, other)
左移 <<
__rshift__(self, other)
右移 >>
__and__(self, other)
按位与 &
__xor__(self, other)
按位异或 ^
__or__(self, other)
按位或 |

6.3 反射(反向)算术运算符

当左操作数不支持相应操作时,Python 会尝试右操作数的反射方法,形式为 __r*__(如 __radd__)。这些方法参数相同,用于实现交换律。

6.4 增量赋值运算符

形式为 __i*__(如 __iadd__),用于 +=-= 等。如果未定义,Python 会退化为普通运算符赋值(a = a + b),但效率较低且可能改变对象身份。

6.5 类型转换

方法
描述
__int__(self)
转换为整数,由 int() 调用
__float__(self)
转换为浮点数,由 float() 调用
__complex__(self)
转换为复数,由 complex() 调用
__bool__(self)
转换为布尔值,由 bool() 调用(未定义时返回 len(self) != 0 或 True
__index__(self)
转换为整数用于切片索引等(必须返回整数),由 operator.index() 调用

完整示例(复数向量类):

import mathclassVector:def__init__(self, x, y):        self.x = x        self.y = ydef__repr__(self):return f"Vector({self.x}{self.y})"# 加法def__add__(self, other):if isinstance(other, Vector):return Vector(self.x + other.x, self.y + other.y)returnNotImplemented# 反射加法(确保 vector + number 可以交换)def__radd__(self, other):return self.__add__(other)   # 如果 other 是标量,可自行处理# 绝对值:模长def__abs__(self):return math.hypot(self.x, self.y)# 布尔值:模长非零def__bool__(self):return bool(abs(self))# 支持向量乘以标量def__mul__(self, scalar):if isinstance(scalar, (int, float)):return Vector(self.x * scalar, self.y * scalar)return NotImplemented    __rmul__ = __mul__   # 交换律v1 = Vector(34)v2 = Vector(12)print(v1 + v2)      # Vector(4, 6)print(2 * v1)       # Vector(6, 8)print(abs(v1))      # 5.0print(bool(v1))     # True

7. 可调用对象

方法
描述
__call__(self[, ...])
使实例可以像函数一样被调用:obj()

示例:

classAdder:def__init__(self, n):        self.n = ndef__call__(self, x):return self.n + xadd_five = Adder(5)print(add_five(3))   # 8print(callable(add_five))  # True

8. 上下文管理器

方法
描述
__enter__(self)
进入 with 块时调用,返回值绑定到 as 后的变量。
__exit__(self, exc_type, exc_value, traceback)
退出 with 块时调用,负责清理资源,返回 True 表示抑制异常。

示例:

classManagedFile:def__init__(self, filename, mode):        self.filename = filename        self.mode = modedef__enter__(self):        self.file = open(self.filename, self.mode)return self.filedef__exit__(self, exc_type, exc_val, exc_tb):if self.file:            self.file.close()if exc_type:            print(f"Exception occurred: {exc_val}")return True# 抑制异常(通常不这样做,除非特殊需求)with ManagedFile('test.txt''w'as f:    f.write('hello')# 文件自动关闭,即使写操作异常也会处理

9. 描述符协议

描述符是实现了特定方法的类,用于管理另一个类的属性访问。常用在 @propertystaticmethodclassmethod 等机制中。

方法
描述
__get__(self, instance, owner)
获取属性值。instance 是拥有该属性的实例,owner 是拥有者类。
__set__(self, instance, value)
设置属性值。
__delete__(self, instance)
删除属性。
__set_name__(self, owner, name)
Python 3.6+,在类创建时被调用,告知描述符在类中的属性名。

示例:

classPositiveNumber:def__set_name__(self, owner, name):        self.name = namedef__get__(self, instance, owner):if instance isNone:return selfreturn instance.__dict__.get(self.name, 0)def__set__(self, instance, value):if value < 0:raise ValueError("Value must be positive")        instance.__dict__[self.name] = valueclassOrder:    quantity = PositiveNumber()    price = PositiveNumber()def__init__(self, quantity, price):        self.quantity = quantity        self.price = pricedeftotal(self):return self.quantity * self.priceorder = Order(105)print(order.total())  # 50# order.quantity = -10  # ValueError

10. 其他常用魔法函数

方法
描述
__instancecheck__(self, instance)
自定义 isinstance() 行为(用于元类)。
__subclasscheck__(self, subclass)
自定义 issubclass() 行为(用于元类)。
__class__
属性,通常返回对象的类,也可通过元类自定义。
__slots__
类变量,限制实例可拥有的属性,节省内存。
__init_subclass__(cls, **kwargs)
Python 3.6+,当子类被创建时调用,用于注册或修改子类。
__set_name__
已在描述符中介绍。
__dir__
已在属性访问中介绍。
__sizeof__(self)
返回对象的内存大小(字节),由 sys.getsizeof() 调用。
__copy__(self)
 和 __deepcopy__(self, memo)
用于支持 copy 模块的自定义复制。
__reduce__(self)
 和 __reduce_ex__(self, protocol)
用于 pickle 序列化。

示例(__slots__):

classPoint:    __slots__ = ('x''y')def__init__(self, x, y):        self.x = x        self.y = yp = Point(12)# p.z = 3  # AttributeError: 'Point' object has no attribute 'z'print(p.__slots__)  # ('x', 'y')

示例(__init_subclass__):

classPluginBase:    plugins = []def__init_subclass__(cls, **kwargs):        super().__init_subclass__(**kwargs)        cls.plugins.append(cls)classPluginA(PluginBase):passclassPluginB(PluginBase):passprint(PluginBase.plugins)  # [<class '__main__.PluginA'>, <class '__main__.PluginB'>]

总结

Python 的魔法函数是语言数据模型的核心,它们允许编写的类无缝集成到 Python 的语法和内置操作中。掌握这些方法不仅可以写出更符合 Python 风格的代码,还能深入理解 Python 内部的工作机制。

使用魔法函数时,应遵循以下原则:

  • 尽量模拟内置类型的行为,保持一致性。
  • 在操作不支持的类型时,返回 NotImplemented 而不是抛出异常,以便 Python 尝试反向操作。
  • 避免过度使用,保持代码简洁可读。
  • 熟悉文档(Python 数据模型)以了解所有细节。

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-03-27 09:54:24 HTTP/2.0 GET : https://f.mffb.com.cn/a/480822.html
  2. 运行时间 : 0.155538s [ 吞吐率:6.43req/s ] 内存消耗:4,937.78kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=e4f8c7053276f48d5b3afbaa7fc23393
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000317s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000484s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000310s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000468s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000490s ]
  6. SELECT * FROM `set` [ RunTime:0.013291s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000975s ]
  8. SELECT * FROM `article` WHERE `id` = 480822 LIMIT 1 [ RunTime:0.002285s ]
  9. UPDATE `article` SET `lasttime` = 1774576464 WHERE `id` = 480822 [ RunTime:0.009402s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.009989s ]
  11. SELECT * FROM `article` WHERE `id` < 480822 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000816s ]
  12. SELECT * FROM `article` WHERE `id` > 480822 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.023566s ]
  13. SELECT * FROM `article` WHERE `id` < 480822 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.003940s ]
  14. SELECT * FROM `article` WHERE `id` < 480822 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.003990s ]
  15. SELECT * FROM `article` WHERE `id` < 480822 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.009438s ]
0.158494s