diff --git a/language/constants.xml b/language/constants.xml index 6d639beb8..10ed5ea6b 100644 --- a/language/constants.xml +++ b/language/constants.xml @@ -1,7 +1,7 @@ - + - + Constantes @@ -38,7 +38,7 @@ Nombres de constantes válidos e inválidos - + ]]> @@ -181,7 +179,6 @@ define("CONSTANT", "Hello world."); echo CONSTANT; // muestra "Hello world." echo Constant; // Lanza un Error: Undefined constant "Constant" // Antes de PHP 8.0.0, muestra "Constant" y emite una advertencia. -?> ]]> @@ -196,23 +193,22 @@ echo Constant; // Lanza un Error: Undefined constant "Constant" // Valor escalar simple const CONSTANT = 'Hello World'; -echo CONSTANT; +echo CONSTANT . "\n"; // Expresión escalar -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]; // muestra "cat" +echo ANIMALS[1] . "\n"; // muestra "cat" // Arrays constantes -define('ANIMALS', array( +define('ANIMALS_DEF', array( 'dog', 'cat', 'bird' )); -echo ANIMALS[1]; // muestra "cat" -?> +echo ANIMALS_DEF[1] . "\n"; // muestra "cat" ]]> diff --git a/language/exceptions.xml b/language/exceptions.xml index 173030e80..718ccb18b 100644 --- a/language/exceptions.xml +++ b/language/exceptions.xml @@ -1,11 +1,14 @@ - + - + Las excepciones + + Vea también la clase Exception + PHP tiene un manejo de excepciones similar al que ofrecen otros lenguajes de programación. @@ -125,7 +128,7 @@ Convertir el error reporting en excepciones - + ]]> @@ -170,7 +172,6 @@ try { // Continuar la ejecución echo "¡Hola mundo!\n"; -?> ]]> &example.outputs; @@ -212,7 +213,6 @@ try { // Continuar la ejecución echo "¡Hola mundo!\n"; -?> ]]> &example.outputs; @@ -243,7 +243,6 @@ function test() { } echo test(); -?> ]]> &example.outputs; @@ -278,8 +277,6 @@ class Test { $foo = new Test; $foo->testing(); - -?> ]]> &example.outputs; @@ -311,8 +308,6 @@ class Test { $foo = new Test; $foo->testing(); - -?> ]]> &example.outputs; @@ -338,7 +333,6 @@ try { } catch (SpecificException) { print "Se lanzó una SpecificException, pero no nos importa con los detalles."; } -?> ]]> &example.outputs; @@ -370,7 +364,6 @@ try { } catch (Exception $e) { print $e->getMessage(); } -?> ]]> &example.outputs; @@ -418,13 +411,13 @@ string(6) "Fourth" Extender las Excepciones Una clase de excepción definida por el usuario puede ser definida extendiendo - la clase Exception integrada. Los miembros y las propiedades a continuación muestran + la clase Exception integrada. Los miembros y las propiedades a continuación muestran lo que está accesible en la clase hija que deriva de la clase Exception integrada. La clase de excepción integrada - + ]]> - Si una clase extiende la clase Exception integrada y redefine el Exception integrada y redefine el constructor, se recomienda fuertemente que también llame a parent::__construct() @@ -533,7 +525,7 @@ class TestException } } -// Ejemplo 1 +echo "# Ejemplo 1\n"; try { $o = new TestException(TestException::THROW_CUSTOM); } catch (MyException $e) { // Será capturada @@ -545,9 +537,9 @@ try { // Continuar la ejecución var_dump($o); // Null -echo "\n\n"; -// Ejemplo 2 + +echo "\n\n# Ejemplo 2\n"; try { $o = new TestException(TestException::THROW_DEFAULT); } catch (MyException $e) { // No coincide con este tipo @@ -559,9 +551,9 @@ try { // Continuar la ejecución var_dump($o); // Null -echo "\n\n"; -// Ejemplo 3 + +echo "\n\n# Ejemplo 3\n"; try { $o = new TestException(TestException::THROW_CUSTOM); } catch (Exception $e) { // Será capturada @@ -570,9 +562,9 @@ try { // Continuar la ejecución var_dump($o); // Null -echo "\n\n"; -// Ejemplo 4 + +echo "\n\n# Ejemplo 4\n"; try { $o = new TestException(); } catch (Exception $e) { // Saltado, ninguna excepción @@ -581,8 +573,6 @@ try { // Continuar la ejecución var_dump($o); // TestException -echo "\n\n"; -?> ]]> diff --git a/language/expressions.xml b/language/expressions.xml index b043ef50f..5af1ec9df 100644 --- a/language/expressions.xml +++ b/language/expressions.xml @@ -1,8 +1,8 @@ - + - + Expresiones La expresiones son los bloques de construcción más importantes de PHP. En PHP @@ -28,7 +28,7 @@ Un ejemplo de expresiones algo más complejo son las funciones. Por ejemplo, considere la siguiente función: - + - + ]]>