PHP Conference Japan 2024

ReflectionClass::getStartLine

(PHP 5, PHP 7, PHP 8)

ReflectionClass::getStartLine取得起始行號

說明

public ReflectionClass::getStartLine(): int|false

取得起始行號。

參數

此函式沒有參數。

回傳值

起始行號,以 int 表示,如果未知則為 false

參見

新增筆記

使用者貢獻的筆記 1 則筆記

info at ensostudio dot ru
3 年前
注意:檔案中的行數從 1 開始!
取得類別程式碼的範例
<?php
$class
= new ReflectionClass('Foo');
$offset = $class->getStartLine() - 1;
$code = implode(
'',
array_slice(
file($class->getFileName()),
$offset,
$class->getEndLine() - $offset
)
);
?>
To Top