diff --git a/language/attributes.xml b/language/attributes.xml index ced697417d32..81f1796c71b3 100644 --- a/language/attributes.xml +++ b/language/attributes.xml @@ -1,6 +1,6 @@ - + Attributes Attributes overview @@ -30,7 +30,7 @@ Implementing optional methods of an interface with Attributes - + Attribute Syntax - + + + &example.outputs; + + @@ -232,10 +236,8 @@ object(MyAttribute)#3 (1) { ["value"]=> int(1234) } -*/ - ]]> - + @@ -250,6 +252,21 @@ object(MyAttribute)#3 (1) { value = $value; + } +} + +#[MyAttribute(value: 1234)] +class Thing +{ +} function dumpMyAttributeData($reflection) { $attributes = $reflection->getAttributes(MyAttribute::class); @@ -280,7 +297,7 @@ dumpMyAttributeData(new ReflectionClass(Thing::class)); Simple Attribute Class - + Using target specification to restrict where attributes can be used - + Using IS_REPEATABLE to allow attribute on a declaration multiple times - + - + Generators @@ -84,7 +84,6 @@ echo 'Single digit odd numbers from xrange(): '; foreach (xrange(1, 9, 2) as $number) { echo "$number "; } -?> ]]> &example.outputs; @@ -166,7 +165,6 @@ $generator = gen_one_to_three(); foreach ($generator as $value) { echo "$value\n"; } -?> ]]> &example.outputs; @@ -230,7 +228,6 @@ foreach (input_parser($input) as $id => $fields) { echo " $fields[0]\n"; echo " $fields[1]\n"; } -?> ]]> &example.outputs; @@ -270,7 +267,6 @@ function gen_three_nulls() { } var_dump(iterator_to_array(gen_three_nulls())); -?> ]]> &example.outputs; @@ -320,7 +316,6 @@ function &gen_reference() { foreach (gen_reference() as &$number) { echo (--$number).'... '; } -?> ]]> &example.outputs; @@ -386,7 +381,6 @@ function gen() { } // pass false as second parameter to get an array [0, 1, 2, 3, 4] var_dump(iterator_to_array(gen())); -?> ]]> &example.outputs; @@ -432,7 +426,6 @@ function eight() { foreach (count_to_ten() as $num) { echo "$num "; } -?> ]]> &example.outputs; @@ -476,7 +469,6 @@ foreach ($gen as $num) { echo "$num "; } echo $gen->getReturn(); -?> ]]> &example.outputs; @@ -501,7 +493,7 @@ echo $gen->getReturn(); - + fileHandle); } } -?> ]]> diff --git a/language/references.xml b/language/references.xml index 7eafdfacfcdb..19842106f9c3 100644 --- a/language/references.xml +++ b/language/references.xml @@ -1,6 +1,6 @@ - + References Explained @@ -38,13 +38,10 @@ In the first of these, PHP references allow you to make two variables refer to the same content. Meaning, when you do: - + ]]> @@ -81,8 +78,6 @@ var_dump(array_key_exists('b', $b)); // bool(true) $c = new stdClass(); foo($c->d); var_dump(property_exists($c, 'd')); // bool(true) - -?> ]]> @@ -92,13 +87,10 @@ var_dump(property_exists($c, 'd')); // bool(true) The same syntax can be used with functions that return references: - + ]]> @@ -120,7 +112,6 @@ $foo =& find_var($bar); ]]> @@ -159,7 +148,6 @@ echo "var2 is set to '$var2'\n"; // var2 is set to 'Example variable' ]]> @@ -185,7 +171,6 @@ echo $ref; // 3 - last element of the iterated array +var_dump($a); +var_dump($b); ]]> @@ -216,6 +201,7 @@ $a = 1; $b =& $a; $c = $b; $c = 7; // $c is not a reference; no change to $a or $b +print "a = {$a}; b = {$b}; c = {$c}\n\n"; /* Assignment of array variables */ $arr = array(1); @@ -224,8 +210,9 @@ $arr2 = $arr; // Not an assignment-by-reference! $arr2[0]++; /* $a == 2, $arr == array(2) */ /* The contents of $arr are changed even though it's not a reference! */ - -?> +print "a = {$a}\n"; +var_dump($arr); +var_dump($arr2); ]]> @@ -245,16 +232,14 @@ $arr2[0]++; +print $a; ]]> @@ -281,18 +266,15 @@ foo($a); As said before, references are not pointers. That means, the following construct won't do what you expect: - + ]]> @@ -322,18 +304,14 @@ foo($bar); +print $a; // $a is 6 here ]]> @@ -364,6 +342,7 @@ foo($a); function foo(&$var) { $var++; + print $var; } function &bar() @@ -373,8 +352,6 @@ function &bar() } foo(bar()); - -?> ]]> @@ -389,7 +366,7 @@ foo(bar()); result is undefined. For example, the following examples of passing by reference are invalid: - + ]]> @@ -449,8 +424,6 @@ $obj = new Foo(); $myValue = &$obj->getValue(); // $myValue is a reference to $obj->value, which is 42 $obj->value = 2; echo $myValue; // Prints the new value of $obj->value, i.e. 2 - -?> ]]> @@ -495,14 +468,17 @@ $collection = &collector(); $collection[] = 'foo'; print_r(collector()); -// Array -// ( -// [0] => foo -// ) - -?> ]]> + &example.outputs; + + foo +) +]]> + @@ -513,7 +489,7 @@ print_r(collector()); To pass the returned reference to another function expecting a reference you can use this syntax: - + ]]> @@ -552,8 +526,8 @@ array_push(collector(), 'foo'); $a = 1; $b =& $a; unset($a); - -?> +var_dump($a); +var_dump($b); ]]> @@ -582,13 +556,10 @@ unset($a); are in fact creating reference to a global variable. That means, this is the same as: - + ]]>