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..a2922e52b29b 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: - + - + ]]>