diff --git a/language/types/array.xml b/language/types/array.xml index a81ce3188f44..d6330168f11a 100644 --- a/language/types/array.xml +++ b/language/types/array.xml @@ -478,16 +478,16 @@ $arr[] = value; // key may be an int or string // value may be any value of any type - + If $arr doesn't exist yet or is set to &null; or &false;, it will be created, so this is also an alternative way to create an array. This practice is however discouraged because if $arr already contains some value (e.g. string from request variable) then this - value will stay in the place and [] may actually stand + value will stay in place and [] may actually stand for string access operator. It is always better to initialize a variable by a direct assignment. - + As of PHP 7.1.0, applying the empty index operator on a string throws a fatal @@ -1052,17 +1052,17 @@ $error_descriptions[8] = "This is just an informal notice"; array($scalarValue). - + If an object is converted to an array, the result is an array whose elements are the object's properties. The keys are the member variable names, with a few notable - exceptions: integer properties are unaccessible; + exceptions: integer properties are inaccessible; private variables have the class name prepended to the variable name; protected variables have a '*' prepended to the variable name. These prepended values have NUL bytes on either side. Uninitialized typed properties are silently discarded. - + Converting to an Array diff --git a/language/types/callable.xml b/language/types/callable.xml index 71df364a1bcb..a5530d55bf5d 100644 --- a/language/types/callable.xml +++ b/language/types/callable.xml @@ -142,7 +142,7 @@ print implode(' ', $new_numbers); Static class methods can be used without instantiating an - object of that class by either, creating an array with + object of that class by either creating an array with the class name at index 0 and the method name at index 1, or by using the special syntax with the scope resolution operator ::, as in 'ClassName::methodName'. @@ -196,7 +196,7 @@ print implode(' ', $new_numbers); - Calling various types of callables with <function>call_user_function</function> + Calling various types of callables with <function>call_user_func</function> TypeError is thrown. - + Every single type that PHP supports, with the exception of - resource can be used within a user-land type declaration. + resource, can be used within a user-land type declaration. This page contains a changelog of availability of the different types and documentation about usage of them in type declarations. - + @@ -137,7 +137,7 @@ Atomic Types Usage Notes - Atomic types have straight forward behaviour with some minor caveats which + Atomic types have straightforward behaviour with some minor caveats which are described in this section. @@ -219,7 +219,8 @@ function &test(): void {} If a pass-by-reference parameter has a type declaration, the type of the variable is only checked on function entry, at the beginning of the call, but not when the function returns. - This means that a function can change the type of variable reference. + This means that a function can change the type of the variable + passed by reference. Typed pass-by-reference Parameters @@ -307,7 +308,7 @@ Stack trace: It is also possible to achieve nullable arguments by making &null; the default value. - This is not recommended as if the default value is changed in a child + This is not recommended because if the default value is changed in a child class a type compatibility violation will be raised as the null type will need to be added to the type declaration. This behavior is also deprecated since PHP 8.4. diff --git a/language/types/float.xml b/language/types/float.xml index 2abe101d3729..65a0d1661c17 100644 --- a/language/types/float.xml +++ b/language/types/float.xml @@ -1,12 +1,12 @@ - Floating point numbers + Floating-point numbers - - Floating point numbers (also known as "floats", "doubles", or "real numbers") + + Floating-point numbers (also known as "floats", "doubles", or "real numbers") can be specified using any of the following syntaxes: - + @@ -42,36 +42,36 @@ EXPONENT_DNUM (({LNUM} | {DNUM}) [eE][+-]? {LNUM}) - Floating point precision + Floating-point precision - - Floating point numbers have limited precision. Although it depends on the + + Floating-point numbers have limited precision. Although it depends on the system, PHP typically uses the IEEE 754 double precision format, which will give a maximum relative error due to rounding in the order of 1.11e-16. - Non elementary arithmetic operations may give larger errors, and, of course, + Non-elementary arithmetic operations may give larger errors, and, of course, error propagation must be considered when several operations are compounded. - + - - Additionally, rational numbers that are exactly representable as floating - point numbers in base 10, like 0.1 or - 0.7, do not have an exact representation as floating - point numbers in base 2, which is used internally, no matter the size of + + Additionally, rational numbers that are exactly representable as floating-point + numbers in base 10, like 0.1 or + 0.7, do not have an exact representation as floating-point + numbers in base 2, which is used internally, no matter the size of the mantissa. Hence, they cannot be converted into their internal binary counterparts without a small loss of precision. This can lead to confusing results: for example, floor((0.1+0.7)*10) will usually return 7 instead of the expected 8, since the internal representation will be something like 7.9999999999999991118.... - + - - So never trust floating number results to the last digit, and do not compare - floating point numbers directly for equality. If higher precision is + + So never trust floating-point number results to the last digit, and do not compare + floating-point numbers directly for equality. If higher precision is necessary, the arbitrary precision math functions and gmp functions are available. - + For a "simple" explanation, see the floating point guide @@ -117,18 +117,18 @@ EXPONENT_DNUM (({LNUM} | {DNUM}) [eE][+-]? {LNUM}) Comparing floats - - As noted in the warning above, testing floating point values for equality is + + As noted in the warning above, testing floating-point values for equality is problematic, due to the way that they are represented internally. However, - there are ways to make comparisons of floating point values that work around + there are ways to make comparisons of floating-point values that work around these limitations. - + - - To test floating point values for equality, an upper bound on the relative + + To test floating-point values for equality, an upper bound on the relative error due to rounding is used. This value is known as the machine epsilon, or unit roundoff, and is the smallest acceptable difference in calculations. - + $a and $b are equal to 5 digits of diff --git a/language/types/integer.xml b/language/types/integer.xml index 426abf6545c8..ef2256093f0c 100644 --- a/language/types/integer.xml +++ b/language/types/integer.xml @@ -12,7 +12,7 @@ &reftitle.seealso; - Floating point numbers + Floating-point numbers Arbitrary precision / BCMath Arbitrary length integer / GMP @@ -29,12 +29,12 @@ can be used to denote a negative int. - + To use octal notation, precede the number with a 0 (zero). As of PHP 8.1.0, octal notation can also be preceded with 0o or 0O. - To use hexadecimal notation precede the number with 0x. - To use binary notation precede the number with 0b. - + To use hexadecimal notation, precede the number with 0x. + To use binary notation, precede the number with 0b. + As of PHP 7.4.0, integer literals may contain underscores (_) between digits, @@ -125,13 +125,13 @@ var_dump(PHP_INT_MAX + 1); // 32-bit system: float(2147483648) Integer division - - There is no int division operator in PHP, to achieve this + + There is no int division operator in PHP. To achieve this, use the intdiv function. 1/2 yields the float 0.5. The value can be cast to an int to round it towards zero, or the round function provides finer control over rounding. - + Divisions @@ -185,7 +185,8 @@ var_dump(round(25/7)); // float(4) When converting from float to int, the number will be rounded towards zero. - As of PHP 8.1.0, a deprecation notice is emitted when implicitly converting a non-integral &float; to &integer; which loses precision. + As of PHP 8.1.0, a deprecation notice is emitted when implicitly converting + a non-integral &float; to an &integer; which loses precision. diff --git a/language/types/iterable.xml b/language/types/iterable.xml index 6e8471131e20..c0319347c933 100644 --- a/language/types/iterable.xml +++ b/language/types/iterable.xml @@ -3,19 +3,19 @@ Iterables - - Iterable is a built-in compile time type alias for + + Iterable is a built-in compile-time type alias for array|Traversable. From its introduction in PHP 7.1.0 and prior to PHP 8.2.0, iterable was a built-in pseudo-type that acted as the - aforementioned type alias and can be used as a type declaration. + aforementioned type alias and could be used as a type declaration. An iterable type can be used in &foreach; and with yield from within a generator. - + diff --git a/language/types/mixed.xml b/language/types/mixed.xml index 3d65f66ddb25..d595d7986cb4 100644 --- a/language/types/mixed.xml +++ b/language/types/mixed.xml @@ -15,10 +15,10 @@ Available as of PHP 8.0.0. - - mixed is, in type theory parlance, the top type. - Meaning every other type is a subtype of it. - + + mixed is, in type theory parlance, the top type, + meaning every other type is a subtype of it. + - type, the value is convertable to a scalar type, + type, the value is convertible to a scalar type, and the coercive typing mode is active (the default), the value may be converted to an accepted scalar value. See below for a description of this behaviour. - + Internal functions - automatically coerce &null; to scalar types, - this behaviour is DEPRECATED as of PHP 8.1.0. + automatically coerce &null; to scalar types. + This behaviour is DEPRECATED as of PHP 8.1.0. @@ -173,14 +173,14 @@ int type declaration: value is interpreted as int - if the conversion is well-defined. For example the string is + if the conversion is well-defined. For example, the string is numeric. float type declaration: value is interpreted as float - if the conversion is well-defined. For example the string is + if the conversion is well-defined. For example, the string is numeric. @@ -240,12 +240,12 @@ - + Types that are not part of the above preference list are not eligible - targets for implicit coercion. In particular no implicit coercions to + targets for implicit coercion. In particular, no implicit coercions to the null, false, and true types occur. - + @@ -352,7 +352,7 @@ var_dump($bar); - The (binary) cast and b prefix exists + The (binary) cast and b prefix exist for forward support. Currently (binary) and (string) are identical, however this may change and should not be relied upon. diff --git a/language/types/type-system.xml b/language/types/type-system.xml index db9f2a9fd673..2d361c3ec609 100644 --- a/language/types/type-system.xml +++ b/language/types/type-system.xml @@ -16,10 +16,10 @@ Atomic types - + Some atomic types are built-in types which are tightly integrated with the - language and cannot be reproduced with user defined types. - + language and cannot be reproduced with user-defined types. + The list of base types is: @@ -159,14 +159,14 @@ Intersection types - - An intersection type accepts values which satisfies multiple + + An intersection type accepts values which satisfy multiple class-type declarations, rather than a single one. Individual types which form the intersection type are joined by the & symbol. Therefore, an intersection type comprised of the types T, U, and V will be written as T&U&V. - + @@ -179,7 +179,7 @@ of the types T, U, and V will be written as T|U|V. If one of the types is an intersection type, it needs to be bracketed - with parenthesis for it to be written in DNF: + with parentheses for it to be written in DNF: T|(X&Y). @@ -188,13 +188,13 @@ Type aliases - + PHP supports two type aliases: mixed and - iterable which corresponds to the + iterable which correspond to the union type of object|resource|array|string|float|int|bool|null and Traversable|array respectively. - + diff --git a/language/types/void.xml b/language/types/void.xml index 5f3bd1025955..60352d2f3e51 100644 --- a/language/types/void.xml +++ b/language/types/void.xml @@ -12,8 +12,8 @@ - Even if a function has a return type of void it will - still return a value, this value is always &null;. + Even if a function has a return type of void, it will + still return a value. This value is always &null;.