略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ReflectionClass::getStartLine

2025-02-27

ReflectionClass::getStartLine

(PHP 5, PHP 7, PHP 8)

ReflectionClass::getStartLine获取起始行号

说明

public ReflectionClass::getStartLine(): int|false

获取起始的行号。

参数

此函数没有参数。

返回值

起始的行号,类型是 int,如果未知,则为 false

参见

添加备注

用户贡献的备注 1 note

up
0
info at ensostudio dot ru
3 years ago
Note: lines in file start from 1!
Sample to get class code:
<?php
$class
= new ReflectionClass('Foo');
$offset = $class->getStartLine() - 1;
$code = implode(
'',
array_slice(
file($class->getFileName()),
$offset,
$class->getEndLine() - $offset
)
);
?>

官方地址:https://www.php.net/manual/en/reflectionclass.getstartline.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3