Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions language/control-structures/foreach.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ foreach ($array as [, , $c]) {
</para>

<para>
A notice will be generated if there aren't enough array elements to fill
A warning will be generated if there aren't enough array elements to fill
the <function>list</function>:

<informalexample>
Expand All @@ -239,10 +239,10 @@ foreach ($array as [$a, $b, $c]) {
&example.outputs;
<screen>
<![CDATA[
Notice: Undefined offset: 2 in example.php on line 7
Warning: Undefined array key 2 in script on line 7
A: 1; B: 2; C:
Notice: Undefined offset: 2 in example.php on line 7
Warning: Undefined array key 2 in script on line 7
A: 3; B: 4; C:
]]>
</screen>
Expand Down
13 changes: 7 additions & 6 deletions language/oop5/anonymous.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ var_dump(new class(10) extends SomeClass implements SomeInterface {
&example.outputs;
<screen>
<![CDATA[
object(class@anonymous)#1 (1) {
["Command line code0x104c5b612":"class@anonymous":private]=>
object(SomeClass@anonymous)#1 (1) {
["num":"SomeClass@anonymous":private]=>
int(10)
}
]]>
Expand Down Expand Up @@ -153,11 +153,12 @@ same class
</informalexample>

<note>
<para>
<simpara>
Note that anonymous classes are assigned a name by the engine, as
demonstrated in the following example. This name has to be regarded an
implementation detail, which should not be relied upon.
</para>
implementation detail, which should not be relied upon. The generated name
contains a NUL byte, which is not visible in the output below.
</simpara>
<informalexample>
<programlisting role="php">
<![CDATA[
Expand All @@ -168,7 +169,7 @@ echo get_class(new class {});
&example.outputs.similar;
<screen>
<![CDATA[
class@anonymous/in/oNi1A0x7f8636ad2021
class@anonymousscript:2$0
]]>
</screen>
</informalexample>
Expand Down
2 changes: 1 addition & 1 deletion language/oop5/magic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ var_dump($c);
&example.outputs;
<screen>
<![CDATA[
string(60) "A::__set_state(array(
string(61) "\A::__set_state(array(
'var1' => 5,
'var2' => 'foo',
))"
Expand Down
14 changes: 9 additions & 5 deletions language/operators/precedence.xml
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ $array[$i] = $i++; // may set either index 1 or 2
<![CDATA[
<?php
$x = 4;
// this line might result in unexpected output:
// "-" binds tighter than ".", so $x-1 is one operand of the concatenation:
echo "x minus one equals " . $x-1 . ", or so I hope\n";

// the desired precedence can be enforced by using parentheses:
// the same grouping, made explicit:
echo "x minus one equals " . ($x-1) . ", or so I hope\n";

// this is not allowed, and throws a TypeError:
Expand All @@ -391,9 +391,13 @@ echo (("x minus one equals " . $x) - 1) . ", or so I hope\n";
&example.outputs;
<screen>
<![CDATA[
-1, or so I hope
-1, or so I hope
Fatal error: Uncaught TypeError: Unsupported operand types: string - int
x minus one equals 3, or so I hope
x minus one equals 3, or so I hope

Fatal error: Uncaught TypeError: Unsupported operand types: string - int in script:10
Stack trace:
#0 {main}
thrown in script on line 10
]]>
</screen>
</example>
Expand Down
2 changes: 1 addition & 1 deletion language/operators/type.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ var_dump(FALSE instanceof stdClass);
bool(false)
bool(false)
bool(false)
PHP Fatal error: instanceof expects an object instance, constant given
bool(false)
]]>
</screen>
</example>
Expand Down
6 changes: 5 additions & 1 deletion language/predefined/backedenum/from.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ $b = Suit::from('B');
<![CDATA[
enum(Suit::Hearts)
Fatal error: Uncaught ValueError: "B" is not a valid backing value for enum "Suit" in /file.php:15
Fatal error: Uncaught ValueError: "B" is not a valid backing value for enum Suit in script:14
Stack trace:
#0 script(14): Suit::from('B')
#1 {main}
thrown in script on line 14
]]>
</screen>
</example>
Expand Down
5 changes: 3 additions & 2 deletions reference/mbstring/functions/mb-detect-encoding.xml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ string(5) "ASCII"
// 'áéóú' encoded in ISO-8859-1
$str = "\xE1\xE9\xF3\xFA";

// The string is not valid ASCII or UTF-8, but UTF-8 is considered a closer match
// The string is valid in neither encoding: non-strict reports the closest
// match, strict returns false
var_dump(mb_detect_encoding($str, ['ASCII', 'UTF-8'], false));
var_dump(mb_detect_encoding($str, ['ASCII', 'UTF-8'], true));

Expand All @@ -191,7 +192,7 @@ var_dump(mb_detect_encoding($str, ['ASCII', 'UTF-8', 'ISO-8859-1'], true));
&example.outputs;
<screen>
<![CDATA[
string(5) "UTF-8"
string(5) "ASCII"
bool(false)
string(10) "ISO-8859-1"
string(10) "ISO-8859-1"
Expand Down
84 changes: 63 additions & 21 deletions reference/reflection/reflectionclass/tostring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ echo $reflectionClass->__toString();
&example.outputs;
<screen>
<![CDATA[
Class [ <internal:Core> class Exception ] {
Class [ <internal:Core> class Exception implements Stringable, Throwable ] {

- Constants [0] {
}
Expand All @@ -58,50 +58,92 @@ Class [ <internal:Core> class Exception ] {
}

- Properties [7] {
Property [ <default> protected $message ]
Property [ <default> private $string ]
Property [ <default> protected $code ]
Property [ <default> protected $file ]
Property [ <default> protected $line ]
Property [ <default> private $trace ]
Property [ <default> private $previous ]
Property [ protected $message = '' ]
Property [ private string $string = '' ]
Property [ protected $code = 0 ]
Property [ protected string $file = '' ]
Property [ protected int $line = 0 ]
Property [ private array $trace = [] ]
Property [ private ?Throwable $previous = NULL ]
}

- Methods [10] {
Method [ <internal:Core> final private method __clone ] {
- Methods [11] {
Method [ <internal:Core> private method __clone ] {

- Parameters [0] {
}
- Return [ void ]
}

Method [ <internal:Core, ctor> public method __construct ] {

- Parameters [3] {
Parameter #0 [ <optional> $message ]
Parameter #1 [ <optional> $code ]
Parameter #2 [ <optional> $previous ]
Parameter #0 [ <optional> string $message = "" ]
Parameter #1 [ <optional> int $code = 0 ]
Parameter #2 [ <optional> ?Throwable $previous = null ]
}
}

Method [ <internal:Core> final public method getMessage ] {
Method [ <internal:Core> public method __wakeup ] {

- Parameters [0] {
}
- Tentative return [ void ]
}

Method [ <internal:Core> final public method getCode ] {
Method [ <internal:Core, prototype Throwable> final public method getMessage ] {

- Parameters [0] {
}
- Return [ string ]
}

Method [ <internal:Core> final public method getFile ] {
Method [ <internal:Core, prototype Throwable> final public method getCode ] {

- Parameters [0] {
}
}

Method [ <internal:Core, prototype Throwable> final public method getFile ] {

- Parameters [0] {
}
- Return [ string ]
}

Method [ <internal:Core> final public method getLine ] {
Method [ <internal:Core, prototype Throwable> final public method getLine ] {

- Parameters [0] {
}
- Return [ int ]
}

Method [ <internal:Core> final public method getTrace ] {
Method [ <internal:Core, prototype Throwable> final public method getTrace ] {

- Parameters [0] {
}
- Return [ array ]
}

Method [ <internal:Core> final public method getPrevious ] {
Method [ <internal:Core, prototype Throwable> final public method getPrevious ] {

- Parameters [0] {
}
- Return [ ?Throwable ]
}

Method [ <internal:Core> final public method getTraceAsString ] {
Method [ <internal:Core, prototype Throwable> final public method getTraceAsString ] {

- Parameters [0] {
}
- Return [ string ]
}

Method [ <internal:Core> public method __toString ] {
Method [ <internal:Core, prototype Stringable> public method __toString ] {

- Parameters [0] {
}
- Return [ string ]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,38 @@ int
</example>

<example>
<title>Usage on built-in functions</title>
<title>Methods with a tentative return type</title>
<programlisting role="php">
<![CDATA[
<?php

$reflection2 = new ReflectionFunction('array_merge');
$reflection2 = new ReflectionMethod('ArrayObject', 'count');

var_dump($reflection2->getReturnType());
echo $reflection2->getTentativeReturnType();
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
null
NULL
int
]]>
</screen>
</example>
</para>
<para>
This is because many internal functions do not have types specified for their
parameters or return values. It is therefore best to avoid using this
method on built-in functions.
A tentative return type is not reported here; use
<methodname>ReflectionFunctionAbstract::getTentativeReturnType</methodname>
to obtain it.
</para>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><methodname>ReflectionFunctionAbstract::getTentativeReturnType</methodname></member>
<member><methodname>ReflectionFunctionAbstract::hasReturnType</methodname></member>
<member><methodname>ReflectionType::__toString</methodname></member>
</simplelist>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,22 @@ bool(true)
</example>

<example>
<title>Usage on built-in functions</title>
<title>Methods with a tentative return type</title>
<programlisting role="php">
<![CDATA[
<?php

$reflection2 = new ReflectionFunction('array_merge');
$reflection2 = new ReflectionMethod('ArrayObject', 'count');

var_dump($reflection2->hasReturnType());
var_dump($reflection2->hasTentativeReturnType());
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
bool(false)
bool(true)
]]>
</screen>
</example>
Expand All @@ -81,6 +83,7 @@ bool(false)
<para>
<simplelist>
<member><methodname>ReflectionFunctionAbstract::getReturnType</methodname></member>
<member><methodname>ReflectionFunctionAbstract::hasTentativeReturnType</methodname></member>
</simplelist>
</para>
</refsect1>
Expand Down