Skip to content

Commit

Permalink
Sync errorexception (#796)
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-records authored Oct 9, 2023
1 parent 67b5d70 commit 8a2f288
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
13 changes: 8 additions & 5 deletions language/predefined/errorexception.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 14767af0f05dffa6fdb9b49e1a1f4e9ca7022a60 Maintainer: mowangjuanzi Status: ready -->
<!-- EN-Revision: e6376e04ed2526138e5b71e16168cf6bb269fa8a Maintainer: mowangjuanzi Status: ready -->
<!-- CREDITS: Luffy -->
<phpdoc:exceptionref xml:id="class.errorexception" xmlns:phpdoc="http://php.net/ns/phpdoc" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xi="http://www.w3.org/2001/XInclude">
<title>ErrorException</title>
<titleabbrev>ErrorException</titleabbrev>
Expand Down Expand Up @@ -82,14 +83,16 @@
<programlisting role="php">
<![CDATA[
<?php
function exception_error_handler($severity, $message, $file, $line) {
if (!(error_reporting() & $severity)) {
function exception_error_handler(int $errno, string $errstr, string $errfile = null, int $errline) {
if (!(error_reporting() & $errno)) {
// 这个错误代码未包含在 error_reporting 中
return;
}
throw new ErrorException($message, 0, $severity, $file, $line);
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");
set_error_handler(exception_error_handler(...));
// 在 PHP 8.1.0 引入 First-class 可调用语法之前,必须使用下面的调用来代替
// set_error_handler(__NAMESPACE__ . "\\exception_error_handler");
/* 触发异常 */
strpos();
Expand Down
4 changes: 2 additions & 2 deletions language/types.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 161dde4fe721309398dd324edbf02aec409f127b Maintainer: dallas Status: ready -->
<!-- EN-Revision: 5fccbe5195820cd9ec0045674312ec567ef5f6ed Maintainer: dallas Status: ready -->
<!-- CREDITS: HonestQiao, Gregory, Haohappy, mowangjuanzi, Luffy -->
<chapter xml:id="language.types" xmlns="http://docbook.org/ns/docbook">
<title>类型</title>
Expand Down Expand Up @@ -109,7 +109,7 @@ int(16)
&language.types.void;
&language.types.never;
&language.types.relative-class-types;
&language.types.literal;
&language.types.value;
&language.types.iterable;
&language.types.declarations;
&language.types.type-juggling;
Expand Down
14 changes: 10 additions & 4 deletions language/types/declarations.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: fc174e8d6162091550edde46159917ee7e5a2e73 Maintainer: avenger Status: ready -->
<!-- EN-Revision: 5fccbe5195820cd9ec0045674312ec567ef5f6ed Maintainer: avenger Status: ready -->
<!-- CREDITS: mowangjuanzi, Luffy -->
<sect1 xml:id="language.types.declarations">
<title>类型声明</title>
Expand Down Expand Up @@ -33,6 +33,12 @@
</row>
</thead>
<tbody>
<row>
<entry>8.3.0</entry>
<entry>
新增了对类、接口和 trait 常量类型的支持。
</entry>
</row>
<row>
<entry>8.2.0</entry>
<entry>
Expand Down Expand Up @@ -123,10 +129,10 @@
</sect2>

<sect2 xml:id="language.types.declarations.base">
<title>基本类型使用说明</title>
<title>原子类型使用说明</title>

<simpara>
Base types have straight forward behaviour with some minor caveats which
Atomic types have straight forward behaviour with some minor caveats which
are described in this section.
</simpara>

Expand Down Expand Up @@ -251,7 +257,7 @@ Stack trace:
<title>联合类型</title>
<warning>
<simpara>
在一个联合类型中不能同时用两个 literal 类型 <type>false</type> 和
在一个联合类型中不能同时用两个 Value 类型 <type>false</type> 和
<type>true</type>。而是使用 <type>bool</type> 替代。
</simpara>
</warning>
Expand Down
15 changes: 8 additions & 7 deletions language/types/type-system.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 999da6fe10dff8f37f7b2dcfab1714bf154f24ce Maintainer: mowangjuanzi Status: ready -->
<!-- EN-Revision: 5fccbe5195820cd9ec0045674312ec567ef5f6ed Maintainer: mowangjuanzi Status: ready -->
<!-- CREDITS: Luffy -->
<sect1 xml:id="language.types.type-system">
<title>类型系统</title>

Expand All @@ -10,14 +11,14 @@
</para>

<para>
PHP 的类型系统支持各种基础类型,可以组合在一起创建更加复杂的类型。其中一些类型可以写成<link
PHP 的类型系统支持各种原子类型,可以组合在一起创建更加复杂的类型。其中一些类型可以写成<link
linkend="language.types.declarations">类型声明</link>。
</para>

<sect2 xml:id="language.types.type-system.base">
<title>基本类型</title>
<sect2 xml:id="language.types.type-system.atomic">
<title>原子类型</title>
<para>
一些基础类型是内置类型,跟语言紧密集成,不能用用户定义类型重现(reproduced)。
一些原子类型是内置类型,跟语言紧密集成,不能用用户定义类型重现(reproduced)。
</para>

<para>
Expand Down Expand Up @@ -73,7 +74,7 @@
</listitem>
<listitem>
<simpara>
<link linkend="language.types.literal">字面量类型</link>
<link linkend="language.types.value">Value 类型</link>
</simpara>
<itemizedlist>
<listitem>
Expand Down Expand Up @@ -110,7 +111,7 @@
<sect2 xml:id="language.types.type-system.composite">
<title>复合类型</title>
<para>
可以将简单类型组合为复合类型。PHP 允许使用以下方式组合类型:
可以将多个原子类型组合为复合类型。PHP 允许使用以下方式组合类型:
</para>

<itemizedlist>
Expand Down
10 changes: 5 additions & 5 deletions language/types/literal.xml → language/types/value.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: f964520a0d2ff23dba3c7a1641f25c180bd25857 Maintainer: mowangjuanzi Status: ready -->
<!-- EN-Revision: 5fccbe5195820cd9ec0045674312ec567ef5f6ed Maintainer: mowangjuanzi Status: ready -->
<!-- CREDITS: Luffy -->
<sect1 xml:id="language.types.literal">
<title>literal 类型</title>
<sect1 xml:id="language.types.value">
<title>Value 类型</title>

<para>
literal 类型是那些不仅检查值,而且也检查值本身的类型。PHP 支持两种 literal 类型:<type>false</type>(自
Value 类型是那些不仅检查值,而且也检查值本身的类型。PHP 支持两种 Value 类型:<type>false</type>(自
PHP 8.0.0 起支持),<type>true</type>(自 PHP 8.2.0 起支持)。
</para>

Expand All @@ -18,7 +18,7 @@

<note>
<simpara>
无法定义自定义 literal 类型。建议改用<link linkend="language.types.enumerations">枚举</link>。
无法定义自定义 Value 类型。建议改用<link linkend="language.types.enumerations">枚举</link>。
</simpara>
</note>

Expand Down

0 comments on commit 8a2f288

Please sign in to comment.