略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ReflectionClass::getStartLine

2024-04-26

ReflectionClass::getStartLine

(PHP 5, PHP 7, PHP 8)

ReflectionClass::getStartLine获取起始行号

说明

public ReflectionClass::getStartLine(): int

获取起始的行号。

警告

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

起始的行号,类型是 integer 的。

参见

add a noteadd a note

User Contributed Notes 1 note

up
0
info at ensostudio dot ru
7 months 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