From 0feec568a3e66675b76882a26be3ec28b3d0009c Mon Sep 17 00:00:00 2001 From: Gwynne Raskind Date: Thu, 21 Feb 2008 18:43:17 +0000 Subject: [PATCH] Major cleanup of language.types.*; mostly grammatical work, some markup and WS fixes, no new content. The title 'Resource' was changed to 'Resources' for consistency; a TOC regen is needed to reflect it. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@253468 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/types.xml | 34 +-- language/types/array.xml | 282 ++++++++++++------------- language/types/boolean.xml | 27 ++- language/types/float.xml | 49 ++--- language/types/integer.xml | 112 +++++----- language/types/null.xml | 17 +- language/types/object.xml | 24 +-- language/types/pseudo-types.xml | 39 ++-- language/types/resource.xml | 37 ++-- language/types/string.xml | 348 +++++++++++++++---------------- language/types/type-juggling.xml | 71 +++---- 11 files changed, 514 insertions(+), 526 deletions(-) diff --git a/language/types.xml b/language/types.xml index 25eeebd81c..616875255f 100644 --- a/language/types.xml +++ b/language/types.xml @@ -1,5 +1,5 @@ - + Types @@ -30,7 +30,7 @@ - float (floating-point number, aka 'double') + float (floating-point number, aka double) @@ -115,27 +115,27 @@ - You may also find some references to the type "double". Consider double the - same as float, the two names exist only for historic reasons. + Some references to the type "double" may remain in the manual. Consider + double the same as float; the two names exist only for historic reasons. - The type of a variable is usually not set by the programmer; rather, it is + The type of a variable is not usually set by the programmer; rather, it is decided at runtime by PHP depending on the context in which that variable is used. - If you want to check out the type and value of a certain - expression, use - var_dump. + To check the type and value of an + expression, use the + var_dump function. - If you simply want a human-readable representation of the type for - debugging, use gettype. To check for a certain type, do - not use gettype, but use the + To get a human-readable representation of a type for debugging, use the + gettype function. To check for a certain type, do + not use gettype, but rather the is_type functions. Some examples: @@ -169,18 +169,18 @@ if (is_string($a_bool)) { - If you would like to force a variable to be converted to a certain type, you - may either cast the - variable or use the settype function on it. + To forcibly convert a variable to a certain type, either + cast the variable or use + the settype function on it. Note that a variable may be evaluated with different values in certain situations, depending on what type it is at the time. For more information, see the section on Type - Juggling. Also, you may be interested in viewing - the type comparison tables, as they - show examples of various type related comparisons. + Juggling. The type comparison + tables may also be useful, as they show examples of various + type-related comparisons. diff --git a/language/types/array.xml b/language/types/array.xml index c1c599fe56..4a6daa34fe 100644 --- a/language/types/array.xml +++ b/language/types/array.xml @@ -1,21 +1,22 @@ - + Arrays - An array in PHP is actually an ordered map. A map is a type that maps - values to keys. This type is - optimized in several ways, so you can use it as a real array, or a list - (vector), hashtable (which is an implementation of a map), dictionary, - collection, stack, queue and probably more. Because you can have another PHP - array as a value, you can also quite easily simulate trees. + An array in PHP is actually an ordered map. A map is a type that + associates values to keys. This type + is optimized for several different uses; it can be treated as an array, + list (vector), hash table (an implementation of a map), dictionary, + collection, stack, queue, and probably more. As array values can + be other arrays, trees and multidimensional arrays + are also possible. Explanation of those data structures is beyond the scope of this manual, but - you'll find at least one example for each of them. For more information we - refer you to external literature about this broad topic. + at least one example is provided for each of them. For more information, look + towards the considerable literature that exists about this broad topic. @@ -26,18 +27,18 @@ An array can be created by the array - language-construct. It takes a certain number of comma-separated + language construct. It takes as parameters any number of comma-separated key => value pairs. array( key => value - , ... - ) -// key may be an integer or string -// value may be any value - + , ... + ) +// key may only be an integer or string +// value may be any value of any type + @@ -58,13 +59,14 @@ echo $arr[12]; // 1 integer, it will be interpreted as such (i.e. "8" will be interpreted as 8, while "08" will be interpreted as "08"). - Floats in key are truncated to integer. - There are no different indexed and associative array types in PHP; there is - only one array type, which can both contain integer and string indices. + Floats in key are truncated to + integer. The indexed and associative array types + are the same type in PHP, which can both contain integer and + string indices. - A value can be of any PHP type. + A value can be any PHP type. @@ -82,10 +84,10 @@ echo $arr["somearray"]["a"]; // 42 - If you do not specify a key for a given value, then the maximum of the - integer indices is taken, and the new key will be that maximum value + 1. If - you specify a key that already has a value assigned to it, that value will - be overwritten. + If a key is not specified for a value, the maximum of the + integer indices is taken and the new key will be that value + plus 1. If a key that already has an assigned value is specified, that value + will be overwritten. @@ -104,55 +106,53 @@ array(5 => 43, 6 => 32, 7 => 56, "b" => 12); - As of PHP 4.3.0, the index generation behaviour described above has - changed. Now, if you append to an array in which the current maximum key is - negative, then the next key created will be zero (0). - Before, the new index would have been set to the largest existing key + 1, - the same as positive indices are. + Before PHP 4.3.0, appending to an array in which the current + maximum key was negative would create a new key as described above. Since + PHP 4.3.0, the new key will be 0. - Using &true; as a key will evaluate to integer - 1 as key. Using &false; as a key will evaluate to - integer 0 as key. Using - NULL as a key will evaluate to the empty string. Using - the empty string as key will create (or overwrite) a key with the empty - string and its value; it is not the same as using empty brackets. + Using &true; as key will evaluate to integer + 1 as a key. Using &false; as key will + evaluate to integer 0 as a key. Using + &null; as a key will evaluate to the empty string. Using the empty string as + a key will create (or overwrite) a key with the empty string and its value; + it is not the same as using empty brackets. - You cannot use arrays or objects as keys. Doing so will result in a warning: - Illegal offset type. + Arrays and objects can not be used as keys. Doing + so will result in a warning: Illegal offset type. - Creating/modifying with square-bracket syntax + Creating/modifying with square bracket syntax - You can also modify an existing array by explicitly setting values in it. + An existing array can be modified by explicitly setting values + in it. - This is done by assigning values to the array while specifying the key in - brackets. You can also omit the key, add an empty pair of brackets - ("[]") to the variable name in that case. + This is done by assigning values to the array, specifying the + key in brackets. The key can also be omitted, resulting in an empty pair of + brackets ([]). $arr[key] = value; $arr[] = value; // key may be an integer or string -// value may be any value - +// value may be any value of any type - If $arr doesn't exist yet, it will be created. So this is - also an alternative way to specify an array. To change a certain value, just - assign a new value to an element specified with its key. If you want to - remove a key/value pair, you need to unset it. + If $arr doesn't exist yet, it will be created, so this is + also an alternative way to create an array. To change a certain + value, assign a new value to that element using its key. To remove a + key/value pair, call the unset function on it. @@ -177,28 +177,18 @@ unset($arr); // This deletes the whole array - As mentioned above, if you provide the brackets with no key specified, then - the maximum of the existing integer indices is taken, and the new key will - be that maximum value + 1 . If no integer indices exist yet, the key will - be 0 (zero). If you specify a key that already has a - value assigned to it, that value will be overwritten. + As mentioned above, if no key is specified, the maximum of the existing + integer indices is taken, and the new key will be that maximum + value plus 1. If no integer indices exist yet, the key will + be 0 (zero). If a key that already has a value is + specified, that value will be overwritten. - - - As of PHP 4.3.0, the index generation behaviour described above has - changed. Now, if you append to an array in which the current maximum key - is negative, then the next key created will be zero - (0). Before, the new index would have been set to the - largest existing key + 1, the same as positive indices are. - - - Note that the maximum integer key used for this need not - currently exist in the array. It simply must have existed in the - array at some time since the last time the array was re-indexed. The - following example illustrates: + currently exist in the array. It need only have + existed in the array at some time since the last time the + array was re-indexed. The following example illustrates: @@ -215,8 +205,7 @@ foreach ($array as $i => $value) { } print_r($array); -// Append an item (note that the new key is 5, instead of 0 as you -// might expect). +// Append an item (note that the new key is 5, instead of 0). $array[] = 6; print_r($array); @@ -269,10 +258,11 @@ Array - The unset function allows unsetting keys of an array. - Be aware that the array will NOT be reindexed. If you only use "usual - integer indices" (starting from zero, increasing by one), you can achieve - the reindex effect by using array_values. + The unset function allows removing keys from an + array. Be aware that the array will not be + reindexed. If a true "remove and shift" behavior is desired, the + array can be reindexed using the + array_values function. @@ -297,8 +287,8 @@ $b = array_values($a); The foreach control - structure exists specifically for arrays. It provides an easy way to traverse - an array. + structure exists specifically for arrays. It provides an easy + way to traverse an array. @@ -309,9 +299,10 @@ $b = array_values($a); Why is <literal>$foo[bar]</literal> wrong? - You should always use quotes around a string literal array index. For - example, use $foo['bar'] and not $foo[bar]. But why is $foo[bar] wrong? You - might have seen the following syntax in old scripts: + Always use quotes around a string literal array index. For example, + $foo['bar'] is correct, while + $foo[bar] is not. But why? It is common to encounter this + kind of syntax in old scripts: @@ -327,22 +318,21 @@ echo $foo[bar]; - This is wrong, but it works. Then, why is it wrong? The reason is that this - code has an undefined constant (bar) rather than a string ('bar' - notice - the quotes), and PHP may in future define constants which, unfortunately for - your code, have the same name. It works because PHP automatically converts - a bare string (an unquoted string which does not - correspond to any known symbol) into a string which contains the bare - string. For instance, if there is no defined constant named - bar, then PHP will substitute in the string - 'bar' and use that. + This is wrong, but it works. The reason is that this code has an undefined + constant (bar) rather than a string ('bar' - notice the + quotes). PHP may in future define constants which, unfortunately for such + code, have the same name. It works because PHP automatically converts a + bare string (an unquoted string which does + not correspond to any known symbol) into a string which + contains the bare string. For instance, if there is no defined + constant named bar, then PHP will substitute in the + string 'bar' and use that. - This does not mean to always quote the key. You do not - want to quote keys which are - constants or + This does not mean to always quote the key. Do not + quote keys which are constants or variables, as this will prevent PHP from interpreting them. @@ -391,14 +381,14 @@ Good: 2 - More examples to demonstrate this fact: + More examples to demonstrate this behaviour: 'apple', 'veggie' => 'carrot'); @@ -407,30 +397,30 @@ $arr = array('fruit' => 'apple', 'veggie' => 'carrot'); print $arr['fruit']; // apple print $arr['veggie']; // carrot -// Incorrect. This works but also throws a PHP error of -// level E_NOTICE because of an undefined constant named fruit +// Incorrect. This works but also throws a PHP error of level E_NOTICE because +// of an undefined constant named fruit // // Notice: Use of undefined constant fruit - assumed 'fruit' in... print $arr[fruit]; // apple -// Let's define a constant to demonstrate what's going on. We -// will assign value 'veggie' to a constant named fruit. +// This defines a constant to demonstrate what's going on. The value 'veggie' +// is assigned to a constant named fruit. define('fruit', 'veggie'); // Notice the difference now print $arr['fruit']; // apple print $arr[fruit]; // carrot -// The following is okay as it's inside a string. Constants are not -// looked for within strings so no E_NOTICE error here +// The following is okay, as it's inside a string. Constants are not looked for +// within strings, so no E_NOTICE occurs here print "Hello $arr[fruit]"; // Hello apple -// With one exception, braces surrounding arrays within strings -// allows constants to be looked for +// With one exception: braces surrounding arrays within strings allows constants +// to be interpreted print "Hello {$arr[fruit]}"; // Hello carrot print "Hello {$arr['fruit']}"; // Hello apple -// This will not work, results in a parse error such as: +// This will not work, and will result in a parse error, such as: // Parse error: parse error, expecting T_STRING' or T_VARIABLE' or T_NUM_STRING' // This of course applies to using superglobals in strings as well print "Hello $arr['fruit']"; @@ -444,18 +434,19 @@ print "Hello " . $arr['fruit']; // Hello apple - When you turn error_reporting up to show - E_NOTICE level errors (such as setting it to - E_ALL) then you will see these errors. By default, - error_reporting is turned down to - not show them. + When error_reporting is set to + show E_NOTICE level errors (by setting it to + E_ALL, for example), such uses will become immediately + visible. By default, + error_reporting is set not to + show notices. As stated in the syntax - section, there must be an expression between the square brackets - ('[' and ']'). That means that you - can write things like this: + section, what's inside the square brackets ('[' and + ']') must be an expression. This means that code like + this works: @@ -470,8 +461,7 @@ echo $arr[somefunc($bar)]; This is an example of using a function return value as the array index. PHP - also knows about constants, as you may have seen the E_* - ones before. + also knows about constants: @@ -508,24 +498,14 @@ $error_descriptions[8] = "This is just an informal notice"; because E_ERROR equals 1, etc. - - As we already explained in the above examples, $foo[bar] - still works but is wrong. It works, because bar is due to - its syntax expected to be a constant expression. However, in this case no - constant with the name bar exists. PHP now assumes that - you meant bar literally, as the string - "bar", but that you forgot to write the quotes. - - So why is it bad then? At some point in the future, the PHP team might want to add another - constant or keyword, or you may introduce another constant into your - application, and then you get in trouble. For example, you already cannot - use the words empty and default this - way, since they are special + constant or keyword, or a constant in other code may interfere. For + example, it is already wrong to use the words empty and + default this way, since they are reserved keywords. @@ -548,18 +528,21 @@ $error_descriptions[8] = "This is just an informal notice"; For any of the types: integer, float, - string, boolean and resource, if you - convert a value to an array, you get an array with one element - (with index 0), which is the scalar value you started with. + string, boolean and resource, + converting a value to an array results in an array with a single + element with index zero and the value of the scalar which was converted. In + other words, (array)$scalarValue is exactly the same as + array($scalarValue). - If you convert an object to an array, you get the properties - (member variables) of that object as the array's elements. The keys are the - member variable names with a few notable exceptions: private variables have - the class name prepended to the variable name; protected variables have a '*' - prepended to the variable name. These prepended values have null bytes on - either side. This can result in some unexpected behaviour. + 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: private variables have the class name prepended to the variable + name; protected variables have a '*' prepended to the variable name. These + prepended values have null bytes on either side. This can result in some + unexpected behaviour: @@ -588,7 +571,8 @@ var_dump((array) new B()); - If you convert a &null; value to an array, you get an empty array. + Converting &null; to an array results in an empty + array. @@ -596,8 +580,9 @@ var_dump((array) new B()); Comparing - It is possible to compare arrays by array_diff and by - Array operators. + It is possible to compare arrays with the array_diff + function and with + array operators. @@ -605,8 +590,7 @@ var_dump((array) new B()); Examples - The array type in PHP is very versatile, so here will be some examples to - show you the full power of arrays. + The array type in PHP is very versatile. Here are some examples: @@ -707,8 +691,8 @@ Do you like yellow? - Changing values of the array directly is possible since PHP 5 by passing them - as reference. Prior versions need workaround: + Changing the values of the array directly is possible since PHP + 5 by passing them by reference. Before that, a workaround is necessary: @@ -790,10 +774,10 @@ closedir($handle); - Arrays are ordered. You can also change the order using various sorting - functions. See the array functions section - for more information. You can count the number of items in an array using the - count function. + Arrays are ordered. The order can be changed using various + sorting functions. See the array functions + section for more information. The count function can be + used to count the number of items in an array. @@ -809,8 +793,9 @@ print_r($files); - Because the value of an array can be anything, it can also be another array. - This way you can make recursive and multi-dimensional arrays. + Because the value of an array can be anything, it can also be + another array. This enables the creation of recursive and + multi-dimensional arrays. @@ -848,10 +833,11 @@ $juices["apple"]["green"] = "good"; - You should be aware that array assignment always involves value copying. It - also means that the internal array pointer used by - current and similar functions is reset. You need to use - the reference operator to copy an array by reference. + Array assignment always involves value copying. It also means + that the internal array pointer used by + current and similar functions is reset. Use the + reference operator to copy an + array by reference. diff --git a/language/types/boolean.xml b/language/types/boolean.xml index 7ce257a664..4898e89cf6 100644 --- a/language/types/boolean.xml +++ b/language/types/boolean.xml @@ -1,24 +1,24 @@ - + Booleans - This is the easiest type. A boolean expresses a truth value. It + This is the simplest type. A boolean expresses a truth value. It can be either &true; or &false;. - The boolean type was introduced in PHP 4. + The boolean type was introduced in PHP 4. Syntax - To specify a boolean literal, use either the keyword &true; or &false;. Both - are case-insensitive. + To specify a boolean literal, use the keywords &true; or + &false;. Both are case-insensitive. @@ -32,9 +32,8 @@ $foo = True; // assign the value TRUE to $foo - Usually you use some kind of - operator which returns a - boolean value, and then pass it on to a + Typically, some kind of operator + which returns a boolean value, and the value is passed on to a control structure. @@ -53,7 +52,7 @@ if ($show_separators == TRUE) { echo "
\n"; } -// ...because you can simply type +// ...because instead, this can be used: if ($show_separators) { echo "
\n"; } @@ -67,11 +66,11 @@ if ($show_separators) { Converting to boolean - To explicitly convert a value to boolean, use either the - (bool) or the (boolean) cast. However, - in most cases you do not need to use the cast, since a value will be - automatically converted if an operator, function or control structure - requires a boolean argument. + To explicitly convert a value to boolean, use the + (bool) or (boolean) casts. However, in + most cases the cast is unncecessary, since a value will be automatically + converted if an operator, function or control structure requires a + boolean argument. diff --git a/language/types/float.xml b/language/types/float.xml index 31ee287590..d729a43d79 100644 --- a/language/types/float.xml +++ b/language/types/float.xml @@ -1,11 +1,11 @@ - + Floating point numbers - Floating point numbers (AKA "floats", "doubles" or "real numbers") can be - specified using any of the following syntaxes: + Floating point numbers (also known as "floats", "doubles", or "real numbers") + can be specified using any of the following syntaxes: @@ -29,14 +29,14 @@ $c = 7E-10; The size of a float is platform-dependent, although a maximum of ~1.8e308 with - a precision of roughly 14 decimal digits is a common value (that's 64 bit IEEE + a precision of roughly 14 decimal digits is a common value (the 64 bit IEEE format). @@ -44,27 +44,27 @@ EXPONENT_DNUM ( ({LNUM} | {DNUM}) [eE][+-]? {LNUM}) Floating point precision - It is quite usual that simple decimal fractions like 0.1 - or 0.7 cannot be converted into their internal binary - counterparts without a little loss of precision. This can lead to confusing + It is typical that simple decimal fractions like 0.1 or + 0.7 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 as - the result of the internal representation really being something like - 7.9999999999.... + return 7 instead of the expected 8, + since the internal representation will be something like + 7.9. - This is related to the fact that it is impossible to exactly express some + This is due to the fact that it is impossible to express some fractions in decimal notation with a finite number of digits. For instance, 1/3 in decimal form becomes - 0.3333333. . .. + 0.3. - So never trust floating number results to the last digit and never compare - floating point numbers for equality. If you really need higher precision, you - should use the arbitrary precision math - functions or gmp functions instead. + So never trust floating number results to the last digit, and never compare + floating point numbers for equality. If higher precision is necessary, + the arbitrary precision math functions and + gmp functions are available. @@ -72,13 +72,14 @@ EXPONENT_DNUM ( ({LNUM} | {DNUM}) [eE][+-]? {LNUM}) Converting to float - For information on when and how strings are converted to floats, see the - section titled String - conversion to numbers. For values of other types, the conversion is - the same as if the value would have been converted to integer and then to - float. See the Converting to - integer section for more information. As of PHP 5, notice is thrown if - you try to convert object to float. + For information on converting strings to float, see + String conversion to + numbers. For values of other types, the conversion is performed by + converting the value to integer first and then to + float. See + Converting to integer + for more information. As of PHP 5, a notice is thrown if an + object is converted to float.
diff --git a/language/types/integer.xml b/language/types/integer.xml index 208142e865..8cd5b05da6 100644 --- a/language/types/integer.xml +++ b/language/types/integer.xml @@ -1,5 +1,5 @@ - + Integers @@ -10,23 +10,38 @@ See also: - Arbitrary length integer / GMP, - Floating point numbers, and - Arbitrary precision / BCMath + + + + Arbitrary length integer / GMP + + + + + Floating point numbers + + + + + Arbitrary precision / BCMath + + + + Syntax - Integers can be specified in decimal (10-based), hexadecimal (16-based) or - octal (8-based) notation, optionally preceded by a sign (- or +). + Integers can be specified in decimal (base 10), hexadecimal + (base 16), or octal (base 8) notation, optionally preceded by a sign + (- or +). - If you use the octal notation, you must precede the number with a - 0 (zero), to use hexadecimal notation precede the number - with 0x. + To use octal notation, precede the number with a 0 (zero). + To use hexadecimal notation precede the number with 0x. @@ -44,7 +59,7 @@ $a = 0x1A; // hexadecimal number (equivalent to 26 decimal) - Formally the possible structure for integer literals is: + Formally, the structure for integer literals is: @@ -65,17 +80,18 @@ integer : [+-]?decimal - The size of an integer is platform-dependent, although a maximum value of - about two billion is the usual value (that's 32 bits signed). PHP does not - support unsigned integers. Integer size can be determined from - PHP_INT_SIZE, maximum value from - PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5. + The size of an integer is platform-dependent, although a maximum + value of about two billion is the usual value (that's 32 bits signed). PHP + does not support unsigned integers. Integer size + can be determined using the constant PHP_INT_SIZE, and + maximum value using the constant PHP_INT_MAX since + PHP 4.4.0 and PHP 5.0.5. - If an invalid digit is passed to octal integer (i.e. 8 or 9), the rest of - the number is ignored. + If an invalid digit is given in an octal integer (i.e. 8 or 9), + the rest of the number is ignored. @@ -95,10 +111,10 @@ var_dump(01090); // 010 octal = 8 decimal Integer overflow - If you specify a number beyond the bounds of the integer type, - it will be interpreted as a float instead. Also, if you perform - an operation that results in a number beyond the bounds of the - integer type, a float will be returned instead. + If PHP encounters a number beyond the bounds of the integer + type, it will be interpreted as a float instead. Also, an + operation which results in a number beyond the bounds of the + integer type will return a float instead. @@ -132,23 +148,22 @@ var_dump($large_number); - Unfortunately, there was a bug in PHP so that this does not always work - correctly when there are negative numbers involved. For example: when you do - -50000 * $million, the result will be - -429496728. However, when both operands are positive - there is no problem. + Unfortunately, there was a bug in PHP which caused this to not always work + correctly when negative numbers were involved. For example, the result of + -50000 * $million is -429496728. + However, when both operands were positive, there was no problem. - This is solved in PHP 4.1.0. + This was fixed in PHP 4.1.0. - There is no integer division operator in PHP. 1/2 yields - the float 0.5. You can cast the value to an - integer to always round it downwards, or you can use the - round function. + There is no integer division operator in PHP. + 1/2 yields the float 0.5. + The value can be casted to an integer to round it downwards, or + the round function provides finer control over rounding. @@ -169,15 +184,15 @@ var_dump(round(25/7)); // float(4) To explicitly convert a value to integer, use either the - (int) or the (integer) cast. However, - in most cases you do not need to use the cast, since a value will be - automatically converted if an operator, function or control structure - requires an integer argument. You can also convert a value to - integer with the function intval. + (int) or (integer) casts. However, in + most cases the cast is not needed, since a value will be automatically + converted if an operator, function or control structure requires an + integer argument. A value can also be converted to + integer with the intval function. - See also type-juggling. + See also: type-juggling. @@ -195,15 +210,16 @@ var_dump(round(25/7)); // float(4) - When converting from float to integer, the number will be rounded - towards zero. + When converting from float to integer, the number + will be rounded towards zero. - If the float is beyond the boundaries of integer (usually + If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31), the result is undefined, since the - float hasn't got enough precision to give an exact integer result. No - warning, not even a notice will be issued in this case! + float doesn't have enough precision to give an exact + integer result. No warning, not even a notice will be issued + when this happens! @@ -223,8 +239,8 @@ echo (int) ( (0.1+0.7) * 10 ); // echoes 7! - See for more information the warning - about float-precision. + See also the warning about float + precision. @@ -243,11 +259,9 @@ echo (int) ( (0.1+0.7) * 10 ); // echoes 7! - Behaviour of converting to integer is undefined for other types. Currently, - the behaviour is the same as if the value was first - converted to boolean. - However, do not rely on this behaviour, as it can - change without notice. + The behaviour of converting to integer is undefined for other + types. Do not rely on any observed behaviour, as it + can change without notice. diff --git a/language/types/null.xml b/language/types/null.xml index b8e64286f1..3b28578c4e 100644 --- a/language/types/null.xml +++ b/language/types/null.xml @@ -1,21 +1,21 @@ - + NULL - The special &null; value represents that a variable has no value. &null; is - the only possible value of type NULL. + The special &null; value represents a variable with no value. &null; is the + only possible value of type NULL. - The null type was introduced in PHP 4. + The null type was introduced in PHP 4. - A variable is considered to be &null; if + A variable is considered to be null if: @@ -40,8 +40,8 @@ Syntax - There is only one value of type &null;, and that is the case-insensitive - keyword &null;. + There is only one value of type null, and that is the + case-insensitive keyword &null;. @@ -55,7 +55,8 @@ $var = NULL; - See also is_null and unset. + See also the functions is_null and + unset. diff --git a/language/types/object.xml b/language/types/object.xml index 3794705f61..3ae37b8063 100644 --- a/language/types/object.xml +++ b/language/types/object.xml @@ -1,5 +1,5 @@ - + Objects @@ -7,8 +7,8 @@ Object Initialization - To initialize an object, you use the new statement to - instantiate the object to a variable. + To create a new object, use the new statement + to instantiate a class: @@ -31,8 +31,8 @@ $bar->do_foo(); - For a full discussion, please read the section - Classes and Objects. + For a full discussion, see the + Classes and Objects chapter. @@ -41,13 +41,13 @@ $bar->do_foo(); Converting to object - If an object is converted to an object, it is not modified. If a value of any - other type is converted to an object, a new instance of the - stdClass built in class is created. If the value was - &null;, the new instance will be empty. Array converts to an object with - properties named by array keys and with corresponding values. For any other - value, a member variable named scalar will contain the - value. + If an object is converted to an object, it is not + modified. If a value of any other type is converted to an + object, a new instance of the stdClass + built-in class is created. If the value was &null;, the new instance will be + empty. Arrays convert to an object with properties + named by keys, and corresponding values. For any other value, a member + variable named scalar will contain the value. diff --git a/language/types/pseudo-types.xml b/language/types/pseudo-types.xml index 77cb84cdfa..04adfccbe4 100644 --- a/language/types/pseudo-types.xml +++ b/language/types/pseudo-types.xml @@ -1,5 +1,5 @@ - + Pseudo-types and variables used in this documentation @@ -13,7 +13,8 @@ gettype for example will accept all PHP types, while - str_replace will accept strings and arrays. + str_replace will accept strings and + arrays. @@ -33,35 +34,36 @@ Some functions like call_user_func or - usort accept user defined callback functions as a - parameter. Callback functions can not only be simple functions but also - object methods including static class methods. + usort accept user-defined callback functions as a + parameter. Callback functions can not only be simple functions, but also + object methods, including static class methods. - A PHP function is simply passed by its name as a string. You can pass any - built-in or user defined function. Note that language constructs like + A PHP function is passed by its name as a string. Any built-in + or user-defined function can be used, except language constructs such as: array, echo, empty, eval, exit, isset, list, print or - unset cannot be called using a callback. + unset. - A method of an instantiated object is passed as an array containing an object - as the element with index 0 and a method name as the element with index 1. + A method of an instantiated object is passed as an + array containing an object at index 0 and the + method name at index 1. - Static class methods can also be passed without instantiating an object of - that class by passing the class name instead of an object as the element with - index 0. + Static class methods can also be passed without instantiating an + object of that class by passing the class name instead of an + object at index 0. Apart from common user-defined function, create_function - can be used to create an anonymous callback function. + can also be used to create an anonymous callback function. @@ -118,8 +120,9 @@ call_user_func(array('B', 'parent::who')); // A - In PHP4, you will have to use a reference to create a callback that points - to the actual object, and not a copy of it. For more details, see + In PHP4, it was necessary to use a reference to create a callback that + points to the actual object, and not a copy of it. For more + details, see References Explained. @@ -130,8 +133,8 @@ call_user_func(array('B', 'parent::who')); // A void - void in return type means that the return value is - useless. void in parameters list means that the function + void as a return type means that the return value is + useless. void in a parameter list means that the function doesn't accept any parameters. diff --git a/language/types/resource.xml b/language/types/resource.xml index b926c3ca05..385a41ec40 100644 --- a/language/types/resource.xml +++ b/language/types/resource.xml @@ -1,32 +1,32 @@ - + - Resource + Resources - A resource is a special variable, holding a reference to an external resource. - Resources are created and used by special functions. See the - appendix for a listing of all these functions - and the corresponding resource types. + A resource is a special variable, holding a reference to an + external resource. Resources are created and used by special functions. See + the appendix for a listing of all these + functions and the corresponding resource types. - The resource type was introduced in PHP 4 + The resource type was introduced in PHP 4 - See also get_resource_type. + See also the get_resource_type function. Converting to resource - As resource types hold special handlers to opened files, database - connections, image canvas areas and the like, you cannot convert any value to - a resource. + As resource variables hold special handlers to opened files, + database connections, image canvas areas and the like, converting to a + resource makes no sense. @@ -34,19 +34,18 @@ Freeing resources - Due to the reference-counting system introduced with PHP 4's Zend Engine, it - is automatically detected when a resource is no longer referred to (just like - Java). When this is the case, all resources that were in use for this resource - are made free by the garbage collector. For this reason, it is rarely ever - necessary to free the memory manually by using some free_result function. + Thanks to the reference-counting system introduced with PHP 4's Zend Engine, + a resource with no more references to it is detected + automatically, and it is freed by the garbage collector. For this reason, it + is rarely necessary to free the memory manually. - Persistent database links are special, they are not - destroyed by the garbage collector. See also the section about + Persistent database links are an exception to this rule. They are + not destroyed by the garbage collector. See the persistent - connections. + connections section for more information. diff --git a/language/types/string.xml b/language/types/string.xml index 871715599d..e9c9c34131 100644 --- a/language/types/string.xml +++ b/language/types/string.xml @@ -1,21 +1,21 @@ - + Strings - A string is series of characters. In PHP, a character is the same - as a byte, that is, there are exactly 256 different characters possible. This - also implies that PHP has no native support of Unicode. See + A string is series of characters. Before PHP 6, a character is + the same as a byte. That is, there are exactly 256 different characters + possible. This also implies that PHP has no native support of Unicode. See utf8_encode and utf8_decode for some - Unicode support. + basic Unicode functionality. - It is no problem for a string to become very large. There is no practical - bound to the size of strings imposed by PHP, so there is no reason at all to - worry about long strings. + It is no problem for a string to become very large. PHP imposes + no boundary on the size of a string; the only limit is the + available memory of the computer on which PHP is running. @@ -23,7 +23,7 @@ Syntax - A string literal can be specified in three different ways. + A string literal can be specified in three different ways: @@ -48,17 +48,16 @@ Single quoted - The easiest way to specify a simple string is to enclose it in single quotes - (the character '). + The simplest way to specify a string is to enclose it in single + quotes (the character '). - To specify a literal single quote, you will need to escape it with a - backslash (\), like in many other languages. If a - backslash needs to occur before a single quote or at the end of the string, - you need to double it. Note that if you try to escape any other character, - the backslash will also be printed! So usually there is no need to escape - the backslash itself. + To specify a literal single quote, escape it with a backslash + (\). To specify a literal backslash before a single + quote, or at the end of the string, double it + (\\). Note that attempting to escape any other character + will print the backslash too. @@ -66,7 +65,7 @@ Unlike the two other syntaxes, variables and escape sequences for special characters will not be expanded when they - occur in single quoted strings. + occur in single quoted strings. @@ -105,8 +104,8 @@ echo 'Variables do not $expand $either'; Double quoted - If the string is enclosed in double-quotes ("), PHP understands more escape - sequences for special characters: + If the string is enclosed in double-quotes ("), PHP will + interpret more escape sequences for special characters: @@ -115,8 +114,8 @@ echo 'Variables do not $expand $either'; - sequence - meaning + Sequence + Meaning @@ -172,14 +171,14 @@ echo 'Variables do not $expand $either';
- Again, if you try to escape any other character, the backslash will be - printed too! Before PHP 5.1.1, backslash in \{$var} - hasn't been printed. + As in single quoted strings, escaping any other character will + result in the backslash being printed too. Before PHP 5.1.1, the backslash + in \{$var} was not been printed. - But the most important feature of double-quoted strings is the fact that - variable names will be expanded. See + The most important feature of double-quoted strings is the fact + that variable names will be expanded. See string parsing for details. @@ -189,44 +188,44 @@ echo 'Variables do not $expand $either'; Heredoc - Another way to delimit strings is by using heredoc syntax ("<<<"). - One should provide an identifier (followed by new line) after - <<<, then the string, and then the same - identifier to close the quotation. + A third way to delimit strings is the heredoc syntax: + <<<. After this operator, an identifier is + provided, then a newline. The string itself follows, and then + the same identifier again to close the quotation. The closing identifier must begin in the first column - of the line. Also, the identifier used must follow the same naming rules as - any other label in PHP: it must contain only alphanumeric characters and + of the line. Also, the identifier must follow the same naming rules as any + other label in PHP: it must contain only alphanumeric characters and underscores, and must start with a non-digit character or underscore. - It is very important to note that the line with the closing identifier - contains no other characters, except possibly a + It is very important to note that the line with the closing identifier must + contain no other characters, except possibly a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces - or tabs after or before the semicolon. It's also important to realize that + or tabs before or after the semicolon. It's also important to realize that the first character before the closing identifier must be a newline as - defined by your operating system. This is \r on - Macintosh for example. Closing delimiter (possibly followed by a semicolon) - must be followed by a newline too. + defined by the local operating system. This is \n on + UNIX systems, including Mac OS X. The closing delimiter (possibly followed + by a semicolon) must also be followed by a newline. - If this rule is broken and the closing identifier is not "clean" then it's - not considered to be a closing identifier and PHP will continue looking for - one. If in this case a proper closing identifier is not found then a parse - error will result with the line number being at the end of the script. + If this rule is broken and the closing identifier is not "clean", it will + not be considered a closing identifier, and PHP will continue looking for + one. If a proper closing identifier is not found before the end of the + current file, a parse error will result at the last line. - It is not allowed to use heredoc syntax in initializing class members. Use - other string syntaxes instead. + Heredocs can not be used for initializing class members. Use other + string syntaxes instead. - + Invalid example @@ -244,11 +243,11 @@ EOT; - Heredoc text behaves just like a double-quoted string, without the - double-quotes. This means that you do not need to escape quotes in your here - docs, but you can still use the escape codes listed above. Variables are + Heredoc text behaves just like a double-quoted string, without + the double quotes. This means that quotes in a heredoc do not need to be + escaped, but the escape codes listed above can still be used. Variables are expanded, but the same care must be taken when expressing complex variables - inside a heredoc as with strings. + inside a heredoc as with strings. @@ -293,23 +292,24 @@ EOT; Heredoc support was added in PHP 4. + Variable parsing - When a string is specified in double quotes or with heredoc, + When a string is specified in double quotes or with heredoc, variables are parsed within it. There are two types of syntax: a - simple one and a + simple one and a complex one. The simple syntax is the most common and convenient. It provides a way to - parse a variable, an array value, or an object - property. + embed a variable, an array value, or an object + property in a string with a minimum of effort. @@ -323,8 +323,8 @@ EOT; If a dollar sign ($) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. - Enclose the variable name in curly braces if you want to explicitly specify - the end of the name. + Enclose the variable name in curly braces to explicitly specify the end of + the name. @@ -332,8 +332,8 @@ EOT; @@ -342,16 +342,10 @@ echo "He drank some {$beer}s"; // works - Similarly, you can also have an array index or an - object property parsed. With array indices, the closing square - bracket (]) marks the end of the index. For object - properties the same rules apply as to simple variables, though with object - properties there doesn't exist a trick like the one with variables. - - + Similarly, an array index or an object property + can be parsed. With array indices, the closing square bracket + (]) marks the end of the index. The same rules apply to + object properties as to simple variables. @@ -359,22 +353,21 @@ echo "He drank some {$beer}s"; // works 'red', 'banana' => 'yellow'); -// Works but note that this works differently outside string-quotes +// Works, but note that this works differently outside a string echo "A banana is $fruits[banana]."; // Works echo "A banana is {$fruits['banana']}."; -// Works but PHP looks for a constant named banana first -// as described below. +// Works, but PHP looks for a constant named banana first, as described below. echo "A banana is {$fruits[banana]}."; // Won't work, use braces. This results in a parse error. @@ -408,24 +401,26 @@ echo "This square is $square->{width}00 centimeters broad."; Complex (curly) syntax - This isn't called complex because the syntax is complex, but because you - can include complex expressions this way. + This isn't called complex because the syntax is complex, but because it + allows for the use of complex expressions. - In fact, you can include any value that is in the namespace in strings with - this syntax. You simply write the expression the same way as you would - outside the string, and then include it in { and }. Since you can't escape - '{', this syntax will only be recognised when the $ is immediately - following the {. (Use "{\$" to get a literal "{$"). Some examples to make - it clear: + In fact, any value in the namespace can be included in a + string with this syntax. Simply write the expression the same + way as it would appeared outside the string, and then wrap it + in { and }. Since + { can not be escaped, this syntax will only be + recognised when the $ immediately follows the + {. Use {\$ to get a literal + {$. Some examples to make it clear: width}00 centimeters broad."; // Works echo "This works: {$arr[4][3]}"; -// This is wrong for the same reason as $foo[bar] is wrong -// outside a string. In other words, it will still work but -// because PHP first looks for a constant named foo, it will -// throw an error of level E_NOTICE (undefined constant). +// This is wrong for the same reason as $foo[bar] is wrong outside a string. +// In other words, it will still work, but only because PHP first looks for a +// constant named foo; an error of level E_NOTICE (undefined constant) will be +// thrown. echo "This is wrong: {$arr[foo][3]}"; -// Works. When using multi-dimensional arrays, always use -// braces around arrays when inside of strings +// Works. When using multi-dimensional arrays, always use braces around arrays +// when inside of strings echo "This works: {$arr['foo'][3]}"; // Works. echo "This works: " . $arr['foo'][3]; -echo "You can even write {$obj->values[3]->name}"; +echo "This works too: {$obj->values[3]->name}"; echo "This is the value of the var named $name: {${$name}}"; @@ -476,16 +471,7 @@ echo "I'd like to have another {${ strrev('reeb') }}, hips"; - Functions and method calls inside {$ } work since PHP 5. - - - - - - Parsing variables within strings uses more memory than string - concatenation. When writing a PHP script in which memory usage is a - concern, consider using the concatenation operator (.) rather than - variable parsing. + Functions and method calls inside {$} work since PHP 5. @@ -496,17 +482,18 @@ echo "I'd like to have another {${ strrev('reeb') }}, hips"; String access and modification by character - Characters within strings may be accessed and modified by specifying the - zero-based offset of the desired character after the string using square - array-brackets like $str[42] so think of a string as an - array of characters. + Characters within strings may be accessed and modified by + specifying the zero-based offset of the desired character after the + string using square array brackets, as in + $str[42]. Think of a string as an + array of characters for this purpose. - They may also be accessed using braces like $str{42} for - the same purpose. However, using square array-brackets is preferred because - the {braces} style is deprecated as of PHP 6. + Strings may also be accessed using braces, as in + $str{42}, for the same purpose. However, this syntax is + deprecated as of PHP 6. Use square brackets instead. @@ -530,9 +517,6 @@ $last = $str[strlen($str)-1]; $str = 'Look at the sea'; $str[strlen($str)-1] = 'e'; -// Alternative method using {} is deprecated as of PHP 6 -$third = $str{2}; - ?> ]]> @@ -540,8 +524,8 @@ $third = $str{2}; - Accessing by [] or {} to - variables of other type silently returns &null;. + Accessing variables of other types using [] or + {} silently returns &null;. @@ -552,33 +536,33 @@ $third = $str{2}; Useful functions and operators - Strings may be concatenated using the '.' (dot) operator. Note that the '+' - (addition) operator will not work for this. Please see - String operators for more - information. + Strings may be concatenated using the '.' (dot) operator. Note + that the '+' (addition) operator will not work for this. + See String operators for + more information. - There are a lot of useful functions for string modification. + There are a number of useful functions for string manipulation. See the string functions section for - general functions, the regular expression functions for advanced find & - replacing (in two tastes: Perl and - POSIX extended). + general functions, and the regular expression + functions or the Perl-compatible regular + expression functions for advanced find & replace functionality. - There are also functions for URL-strings, and + There are also functions for URL strings, and functions to encrypt/decrypt strings (mcrypt and mhash). - Finally, if you still didn't find what you're looking for, see also the - character type functions. + Finally, see also the character type + functions. @@ -586,62 +570,63 @@ $third = $str{2}; Converting to string - You can convert a value to a string using the (string) - cast, or the strval function. String conversion is - automatically done in the scope of an expression for you where a string is - needed. This happens when you use the echo or - print functions, or when you compare a variable value to - a string. Reading the manual sections on + A value can be converted to a string using the + (string) cast or the strval function. + String conversion is automatically done in the scope of an + expression where a string is needed. This happens when using the + echo or print functions, or when a + variable is compared to a string. The sections on Types and Type Juggling will make - the following clearer. See also settype. + the following clearer. See also the settype function. - A boolean &true; value is converted to the string - "1", the &false; value is represented as - "" (empty string). This way you can convert back and forth - between boolean and string values. + A boolean &true; value is converted to the string + "1". Boolean &false; is converted to + "" (the empty string). This allows conversion back and + forth between boolean and string values. - An integer or a floating point number (float) is - converted to a string representing the number with its digits (including the - exponent part for floating point numbers). Floating point numbers can be - converted using the exponential notation (4.1E+6). + An integer or float is converted to a + string representing the number textually (including the + exponent part for floats). Floating point numbers can be + converted using exponential notation (4.1E+6). The decimal point character is defined in the script's locale (category - LC_NUMERIC). See setlocale. + LC_NUMERIC). See the setlocale function. - Arrays are always converted to the string "Array", so you - cannot dump out the contents of an array with - echo or print to see what is inside - them. To view one element, you'd do something like - echo $arr['foo']. See below for tips on dumping/viewing - the entire contents. + Arrays are always converted to the string + "Array"; because of this, echo and + print can not by themselves show the contents of an + array. To view a single element, use a construction such as + echo $arr['foo']. See below for tips on viewing the entire + contents. - Objects in PHP 4 are always converted to the string - "Object". If you would like to print out the member - variable values of an object for debugging reasons, read the - paragraphs below. If you would like to find out the class name of which an - object is an instance of, use get_class. As of PHP 5, - __toString() method is used if applicable. + Objects in PHP 4 are always converted to the string + "Object". To print the values of object members for + debugging reasons, read the paragraphs below. To get an object's class name, + use the get_class function. As of PHP 5, the + __toString method is used when + applicable. - Resources are always converted to strings with the structure - "Resource id #1" where 1 is the unique - number of the resource assigned by PHP during runtime. If you - would like to get the type of the resource, use - get_resource_type. + Resources are always converted to strings with the + structure "Resource id #1", where 1 is + the unique number assigned to the resource by PHP at runtime. Do + not rely upon this structure; it is subject to change. To get a + resource's type, use the + get_resource_type function. @@ -649,40 +634,44 @@ $third = $str{2}; - As you can see above, printing out the arrays, objects or resources does not - provide you any useful information about the values themselves. Look at the + As stated above, directly converting an array, + object, or resource to a string does + not provide any useful information about the value beyond its type. See the functions print_r and var_dump for - better ways to print out values for debugging. + more effective means of inspecting the contents of these types. - You can also convert PHP values to strings to store them permanently. This - method is called serialization, and can be done with the function - serialize. You can also serialize PHP values to XML - structures, if you have WDDX support in your - PHP setup. + Most PHP values can also be converted to strings for permanent + storage. This method is called serialization, and is performed by the + serialize function. If the PHP engine was built with + WDDX support, PHP values can also be + serialized as well-formed XML text. + String conversion to numbers - When a string is evaluated as a numeric value, the resulting value and type - are determined as follows. + When a string is evaluated in a numeric context, the resulting + value and type are determined as follows. - The string will evaluate as a float if it contains any of the - characters '.', 'e', or 'E'. Otherwise, it will evaluate as an integer. + The string will be evaluated as a float if it + contains any of the characters '.', 'e', or 'E'. Otherwise, it will be + evaluated as an integer. - The value is given by the initial portion of the string. If the string starts - with valid numeric data, this will be the value used. Otherwise, the value - will be 0 (zero). Valid numeric data is an optional sign, followed by one or - more digits (optionally containing a decimal point), followed by an optional - exponent. The exponent is an 'e' or 'E' followed by one or more digits. + The value is given by the initial portion of the string. If the + string starts with valid numeric data, this will be the value + used. Otherwise, the value will be 0 (zero). Valid numeric data is an + optional sign, followed by one or more digits (optionally containing a + decimal point), followed by an optional exponent. The exponent is an 'e' or + 'E' followed by one or more digits. @@ -708,9 +697,8 @@ $foo = "10.0 pigs " + 1.0; // $foo is float (11) - If you would like to test any of the examples in this section, you can cut - and paste the examples and insert the following line to see for yourself - what's going on: + To test any of the examples in this section, cut and paste the examples and + insert the following line to see what's going on: @@ -724,10 +712,10 @@ echo "\$foo==$foo; type is " . gettype ($foo) . "
\n";
- Do not expect to get the code of one character by converting it to integer - (as you would do in C for example). Use the functions - ord and chr to convert between - charcodes and characters. + Do not expect to get the code of one character by converting it to integer, + as is done in C. Use the ord and + chr functions to convert between ASCII codes and + characters. diff --git a/language/types/type-juggling.xml b/language/types/type-juggling.xml index 317c2326de..f88317080e 100644 --- a/language/types/type-juggling.xml +++ b/language/types/type-juggling.xml @@ -1,24 +1,25 @@ - + Type Juggling PHP does not require (or support) explicit type definition in variable - declaration; a variable's type is determined by the context in which that - variable is used. That is to say, if you assign a string value to variable - $var, $var becomes a string. If - you then assign an integer value to $var, it becomes an - integer. + declaration; a variable's type is determined by the context in which the + variable is used. That is to say, if a string value is assigned + to variable $var, $var becomes a + string. If an integer value is then assigned to + $var, it becomes an integer. An example of PHP's automatic type conversion is the addition operator '+'. - If any of the operands is a float, then all operands are evaluated as floats, - and the result will be a float. Otherwise, the operands will be interpreted as - integers, and the result will also be an integer. Note that this does NOT + If either operand is a float, then both operands are evaluated as + floats, and the result will be a float. Otherwise, + the operands will be interpreted as integers, and the result will + also be an integer. Note that this does not change the types of the operands themselves; the only change is in how the - operands are evaluated. + operands are evaluated and what the type of the expression itself is. @@ -61,24 +62,26 @@ examples: - If you wish to force a variable to be evaluated as a certain type, see the - section on Type casting. If - you wish to change the type of a variable, see settype. + To force a variable to be evaluated as a certain type, see the section on + Type casting. To change the + type of a variable, see the settype function. + - If you would like to test any of the examples in this section, you - can use the var_dump function. + To test any of the examples in this section, use the + var_dump function. - The behaviour of an automatic conversion to array is currently undefined. + The behaviour of an automatic conversion to array is currently + undefined. - Also, because PHP supports indexing into strings via offsets using the same - syntax as array indexing, the following example holds true for all PHP - versions: + Also, because PHP supports indexing into strings via offsets + using the same syntax as array indexing, the following example + holds true for all PHP versions: @@ -124,25 +127,25 @@ $bar = (boolean) $foo; // $bar is a boolean - (int), (integer) - cast to integer + (int), (integer) - cast to integer - (bool), (boolean) - cast to boolean + (bool), (boolean) - cast to boolean - (float), (double), (real) - cast to float + (float), (double), (real) - cast to float - (string) - cast to string + (string) - cast to string - (binary) - cast to binary string (PHP 6) + (binary) - cast to binary string (PHP 6) - (array) - cast to array + (array) - cast to array - (object) - cast to object + (object) - cast to object @@ -166,7 +169,8 @@ $foo = ( int ) $bar; - Casting a literal strings and variables to binary strings: + Casting literal strings and variables to binary + strings: @@ -181,8 +185,8 @@ $binary = b"binary string"; - Instead of casting a variable to string, you can also enclose the variable - in double quotes. + Instead of casting a variable to a string, it is also possible + to enclose the variable in double quotes. @@ -205,7 +209,7 @@ if ($fst === $str) { It may not be obvious exactly what will happen when casting between certain - types. For more info, see these sections: + types. For more information, see these sections: @@ -245,13 +249,6 @@ if ($fst === $str) { resource - The type comparison tables