From 1032d7d414bb54f739dc410b38c3fa9b057f6843 Mon Sep 17 00:00:00 2001 From: AllenJB Date: Thu, 2 Apr 2026 16:27:24 +0100 Subject: [PATCH 1/2] Enable runnable (WASM) examples for language sections: constants, exceptions, expressions --- language/constants.xml | 20 ++++++++------------ language/exceptions.xml | 37 ++++++++++++------------------------- language/expressions.xml | 17 +++++++++++++---- language/fibers.xml | 1 - 4 files changed, 33 insertions(+), 42 deletions(-) diff --git a/language/constants.xml b/language/constants.xml index 094512ae24d9..ad7f95423326 100644 --- a/language/constants.xml +++ b/language/constants.xml @@ -1,6 +1,6 @@ - + Constants @@ -36,7 +36,7 @@ Valid and invalid constant names - + ]]> @@ -178,7 +176,6 @@ define("CONSTANT", "Hello world."); echo CONSTANT; // outputs "Hello world." echo Constant; // Emits an Error: Undefined constant "Constant" // Prior to PHP 8.0.0, outputs "Constant" and issues a warning. -?> ]]> @@ -193,23 +190,22 @@ echo Constant; // Emits an Error: Undefined constant "Constant" // Simple scalar value const CONSTANT = 'Hello World'; -echo CONSTANT; +echo CONSTANT . "\n"; // Scalar expression -const ANOTHER_CONST = CONSTANT.'; Goodbye World'; -echo ANOTHER_CONST; +const ANOTHER_CONST = CONSTANT . '; Goodbye World'; +echo ANOTHER_CONST . "\n"; const ANIMALS = array('dog', 'cat', 'bird'); -echo ANIMALS[1]; // outputs "cat" +echo ANIMALS[1] . "\n"; // outputs "cat" // Constant arrays -define('ANIMALS', array( +define('ANIMALS_DEF', array( 'dog', 'cat', 'bird' )); -echo ANIMALS[1]; // outputs "cat" -?> +echo ANIMALS_DEF[1] . "\n"; // outputs "cat" ]]> diff --git a/language/exceptions.xml b/language/exceptions.xml index 4ffefcb55660..4e2a24cf0baa 100644 --- a/language/exceptions.xml +++ b/language/exceptions.xml @@ -1,7 +1,10 @@ - + Exceptions + + See also the Exception class + PHP has an exception model similar to that of other programming languages. An exception can be &throw;n, and caught ("&catch;ed") within @@ -112,7 +115,7 @@ Converting error reporting to exceptions - + ]]> @@ -158,7 +160,6 @@ try { // Continue execution echo "Hello World\n"; -?> ]]> &example.outputs; @@ -200,7 +201,6 @@ try { // Continue execution echo "Hello World\n"; -?> ]]> &example.outputs; @@ -231,7 +231,6 @@ function test() { } echo test(); -?> ]]> &example.outputs; @@ -266,8 +265,6 @@ class Test { $foo = new Test; $foo->testing(); - -?> ]]> &example.outputs; @@ -299,8 +296,6 @@ class Test { $foo = new Test; $foo->testing(); - -?> ]]> &example.outputs; @@ -328,7 +323,6 @@ try { } catch (SpecificException) { print "A SpecificException was thrown, but we don't care about the details."; } -?> ]]> &example.outputs; @@ -358,7 +352,6 @@ try { } catch (Exception $e) { print $e->getMessage(); } -?> ]]> &example.outputs; @@ -406,12 +399,12 @@ string(6) "Fourth" Extending Exceptions A User defined Exception class can be defined by extending the built-in - Exception class. The members and properties below, show what is accessible + Exception class. The members and properties below, show what is accessible within the child class that derives from the built-in Exception class. The Built in Exception class - + ]]> - If a class extends the built-in Exception class and re-defines the Exception class and re-defines the constructor, it is highly recommended that it also call parent::__construct() @@ -521,7 +513,7 @@ class TestException } -// Example 1 +echo "# Example 1\n"; try { $o = new TestException(TestException::THROW_CUSTOM); } catch (MyException $e) { // Will be caught @@ -533,10 +525,9 @@ try { // Continue execution var_dump($o); // Null -echo "\n\n"; -// Example 2 +echo "\n\n# Example 2\n"; try { $o = new TestException(TestException::THROW_DEFAULT); } catch (MyException $e) { // Doesn't match this type @@ -548,10 +539,9 @@ try { // Continue execution var_dump($o); // Null -echo "\n\n"; -// Example 3 +echo "\n\n# Example 3\n"; try { $o = new TestException(TestException::THROW_CUSTOM); } catch (Exception $e) { // Will be caught @@ -560,10 +550,9 @@ try { // Continue execution var_dump($o); // Null -echo "\n\n"; -// Example 4 +echo "\n\n# Example 4\n"; try { $o = new TestException(); } catch (Exception $e) { // Skipped, no exception @@ -572,8 +561,6 @@ try { // Continue execution var_dump($o); // TestException -echo "\n\n"; -?> ]]> diff --git a/language/expressions.xml b/language/expressions.xml index ed937167113e..ca0cfc265b15 100644 --- a/language/expressions.xml +++ b/language/expressions.xml @@ -1,6 +1,6 @@ - + Expressions Expressions are the most important building blocks of PHP. In PHP, @@ -26,7 +26,7 @@ Slightly more complex examples for expressions are functions. For instance, consider the following function: - + - + ]]> diff --git a/language/fibers.xml b/language/fibers.xml index eae91489d4c6..424616c43ee3 100644 --- a/language/fibers.xml +++ b/language/fibers.xml @@ -57,7 +57,6 @@ $value = $fiber->start(); echo "Value from fiber suspending: ", $value, PHP_EOL; $fiber->resume('test'); -?> ]]> &example.outputs; From 34e63b30e6d8ed4ff0840c328dcc917fff0e2759 Mon Sep 17 00:00:00 2001 From: AllenJB Date: Sat, 4 Apr 2026 09:03:29 +0100 Subject: [PATCH 2/2] Enable runnable (WASM) examples for language sections: constants, exceptions, expressions Review amends: => ; Remove cosmetic change on otherwise untouched fibers page --- language/exceptions.xml | 6 +++--- language/fibers.xml | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/language/exceptions.xml b/language/exceptions.xml index 4e2a24cf0baa..a2922e52b29b 100644 --- a/language/exceptions.xml +++ b/language/exceptions.xml @@ -3,7 +3,7 @@ Exceptions - See also the Exception class + See also the Exception class PHP has an exception model similar to that of other programming @@ -399,7 +399,7 @@ string(6) "Fourth" Extending Exceptions A User defined Exception class can be defined by extending the built-in - Exception class. The members and properties below, show what is accessible + Exception class. The members and properties below, show what is accessible within the child class that derives from the built-in Exception class. @@ -436,7 +436,7 @@ class Exception implements Throwable - If a class extends the built-in Exception class and re-defines the Exception class and re-defines the constructor, it is highly recommended that it also call parent::__construct() diff --git a/language/fibers.xml b/language/fibers.xml index 424616c43ee3..eae91489d4c6 100644 --- a/language/fibers.xml +++ b/language/fibers.xml @@ -57,6 +57,7 @@ $value = $fiber->start(); echo "Value from fiber suspending: ", $value, PHP_EOL; $fiber->resume('test'); +?> ]]> &example.outputs;