PHP的Exception
创始人
2024-02-06 13:04:04
0

# 简单解释
Exception是PHP的内置类,用来处理异常的基类
https://www.php.net/manual/zh/class.exception.php

```php
class Exception implements Throwable {  
    /** The error message */  
    protected $message;  
    /** The error code */  
    protected $code;  
    /** The filename where the error happened  */  
    protected $file;  
    /** The line where the error happened */  
    protected $line;  
 
 
    /**  
     * Clone the exception     * Tries to clone the Exception, which results in Fatal error.     * @link https://php.net/manual/en/exception.clone.php  
     * @return void  
     */    final private function __clone() { }  
 
    /**  
     * Construct the exception. Note: The message is NOT binary safe.     * @link https://php.net/manual/en/exception.construct.php  
     * @param string $message [optional] The Exception message to throw.  
     * @param int $code [optional] The Exception code.  
     * @param null|Throwable $previous [optional] The previous throwable used for the exception chaining.  
     */    #[Pure]  
    public function __construct($message = "", $code = 0, Throwable $previous = null) { }  
 
    /**  
     * Gets the Exception message     * @link https://php.net/manual/en/exception.getmessage.php  
     * @return string the Exception message as a string.  
     */    #[Pure]  
    final public function getMessage() { }  
 
    /**  
     * Gets the Exception code     * @link https://php.net/manual/en/exception.getcode.php  
     * @return mixed|int the exception code as integer in  
     * Exception but possibly as other type in  
     * Exception descendants (for example as  
     * string in PDOException).  
     */    #[Pure]  
    final public function getCode() { }  
 
    /**  
     * Gets the file in which the exception occurred     * @link https://php.net/manual/en/exception.getfile.php  
     * @return string the filename in which the exception was created.  
     */    #[Pure]  
    final public function getFile() { }  
 
    /**  
     * Gets the line in which the exception occurred     * @link https://php.net/manual/en/exception.getline.php  
     * @return int the line number where the exception was created.  
     */    #[Pure]  
    final public function getLine() { }  
 
    /**  
     * Gets the stack trace     * @link https://php.net/manual/en/exception.gettrace.php  
     * @return array the Exception stack trace as an array.  
     */    #[Pure]  
    final public function getTrace() { }  
 
    /**  
     * Returns previous Exception     * @link https://php.net/manual/en/exception.getprevious.php  
     * @return Exception the previous Exception if available  
     * or null otherwise.     */    #[Pure]  
    final public function getPrevious() { }  
 
    /**  
     * Gets the stack trace as a string     * @link https://php.net/manual/en/exception.gettraceasstring.php  
     * @return string the Exception stack trace as a string.  
     */    #[Pure]  
    final public function getTraceAsString() { }  
 
    /**  
     * String representation of the exception     * @link https://php.net/manual/en/exception.tostring.php  
     * @return string the string representation of the exception.  
     */    public function __toString() { }  
 
    public function __wakeup() { }  
}
```

我这里去看看__toString方法
https://www.php.net/manual/zh/exception.tostring.php

看图就好了


 


 

# 直接来命令执行:
```php
$a= new Exception(phpinfo());  
echo $a;```

就会输出phpinfo
直接命令执行就很好。
```php
$a= new Exception(system('whoami'));  
echo $a;```

```php
$a= new Exception(system("dir"));  
echo $a->__toString();
```
还挺万能东西

# CTF题
有挺多的,懒得列了

相关内容

热门资讯

喜欢穿一身黑的男生性格(喜欢穿... 今天百科达人给各位分享喜欢穿一身黑的男生性格的知识,其中也会对喜欢穿一身黑衣服的男人人好相处吗进行解...
发春是什么意思(思春和发春是什... 本篇文章极速百科给大家谈谈发春是什么意思,以及思春和发春是什么意思对应的知识点,希望对各位有所帮助,...
网络用语zl是什么意思(zl是... 今天给各位分享网络用语zl是什么意思的知识,其中也会对zl是啥意思是什么网络用语进行解释,如果能碰巧...
为什么酷狗音乐自己唱的歌不能下... 本篇文章极速百科小编给大家谈谈为什么酷狗音乐自己唱的歌不能下载到本地?,以及为什么酷狗下载的歌曲不是...
华为下载未安装的文件去哪找(华... 今天百科达人给各位分享华为下载未安装的文件去哪找的知识,其中也会对华为下载未安装的文件去哪找到进行解...
家里可以做假山养金鱼吗(假山能... 今天百科达人给各位分享家里可以做假山养金鱼吗的知识,其中也会对假山能放鱼缸里吗进行解释,如果能碰巧解...
四分五裂是什么生肖什么动物(四... 本篇文章极速百科小编给大家谈谈四分五裂是什么生肖什么动物,以及四分五裂打一生肖是什么对应的知识点,希...
怎么往应用助手里添加应用(应用... 今天百科达人给各位分享怎么往应用助手里添加应用的知识,其中也会对应用助手怎么添加微信进行解释,如果能...
客厅放八骏马摆件可以吗(家里摆... 今天给各位分享客厅放八骏马摆件可以吗的知识,其中也会对家里摆八骏马摆件好吗进行解释,如果能碰巧解决你...
美团联名卡审核成功待激活(美团... 今天百科达人给各位分享美团联名卡审核成功待激活的知识,其中也会对美团联名卡审核未通过进行解释,如果能...