略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: ParseError

2024-11-22

ParseError

(PHP 7, PHP 8)

简介

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

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

类摘要

class ParseError extends CompileError {
/* 继承的属性 */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
private ?Throwable $previous = null;
/* 继承的方法 */
final public Error::getMessage(): string
final public Error::getPrevious(): ?Throwable
final public Error::getCode(): int
final public Error::getFile(): string
final public Error::getLine(): int
final public Error::getTrace(): array
final public Error::getTraceAsString(): string
public Error::__toString(): string
private Error::__clone(): void
}
add a noteadd a note

User Contributed Notes 1 note

up
2
andrian dot test dot job at gmail dot com
2 years ago
<?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'");

*/

官方地址:https://www.php.net/manual/en/class.parseerror.php

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