总有人间一两风,填我十万八千梦

PHP ParseError 用法 手册 | 示例代码

PHP开发手册 归档 209℃ 0评论

ParseError

(PHP 7, PHP 8)

简介

ParseError 当解析 PHP 代码时发生错误时抛出,比如当 eval()被调用出错时。

注意: 从 PHP 7.3.0 开始,ParseError 继承自 CompileError。之前的版本,则继承自 Error

类摘要

ParseError extends CompileError {
/* 继承的属性 */
protected string $message;
protected int $code;
protected string $file;
protected int $line;
/* 继承的方法 */
final public Error::getMessage(): string
final public Error::getCode(): mixed
final public Error::getFile(): string
final public Error::getLine(): int
final public Error::getTrace(): array
final public Error::getTraceAsString(): string
public Error::__toString(): string
final private Error::__clone(): void

}

用户贡献的笔记

andrian dot test dot job at gmail dot com

<?php
/*
* The function eval() evaluate his argument as an instruction PHP
* Then the argument must respect the standar of PHP codage
* In this example the semicolon are missign
*/

try{

    eval("echo 'toto' echo 'tata'");

}catch(ParseError $p){

    echo $p->getMessage();
}

/*
* If you run this code the result is different of the result of above code
* PHP will output the standar parse Error: syntax error, ....
*

eval("echo 'toto' echo 'tata'");

*/

转载请注明:悠然品鉴 » PHP ParseError 用法 手册 | 示例代码

喜欢 (0)or分享 (0)
发表我的评论
取消评论

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址