= PHP_5_5_0, PHP_7, PHP_8 // debug_zval_dump() - PHP_4 >= PHP_4_2_0, PHP_5, PHP_7, PHP_8 // doubleval() - PHP_4, PHP_5, PHP_7, PHP_8 // empty() - PHP_4, PHP_5, PHP_7, PHP_8 // floatval() - PHP_4 >= PHP_4_2_0, PHP_5, PHP_7, PHP_8 // OFFLINE | get_debug_type() - PHP_8 // get_defined_vars() - PHP_4 >= PHP_4_0_4, PHP_5, PHP_7, PHP_8 // OFFLINE | get_resource_id() - PHP_8 // get_resource_type() - PHP_4 >= PHP_4_0_2, PHP_5, PHP_7, PHP_8 // gettype() - PHP_4, PHP_5, PHP_7, PHP_8 // intval() - PHP_4, PHP_5, PHP_7, PHP_8 // is_array() - PHP_4, PHP_5, PHP_7, PHP_8 // is_bool() - PHP_4, PHP_5, PHP_7, PHP_8 // is_callable() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // OFFLINE | is_countable() - PHP_7 >= PHP_7_3_0, PHP_8 // is_double() - PHP_4, PHP_5, PHP_7, PHP_8 // is_float() - PHP_4, PHP_5, PHP_7, PHP_8 // is_int() - PHP_4, PHP_5, PHP_7, PHP_8 // is_integer() - PHP_4, PHP_5, PHP_7, PHP_8 // OFFLINE | is_iterable() - PHP_7 >= PHP_7_1_0, PHP_8 // is_long() - PHP_4, PHP_5, PHP_7, PHP_8 // is_null() - PHP_4 >= PHP_4_0_4, PHP_5, PHP_7, PHP_8 // is_numeric() - PHP_4, PHP_5, PHP_7, PHP_8 // is_object() - PHP_4, PHP_5, PHP_7, PHP_8 // is_real() - PHP_4, PHP_5, PHP_7, PHP_8 // is_resource() - PHP_4, PHP_5, PHP_7, PHP_8 // is_scalar() - PHP_4 >= PHP_4_0_5, PHP_5, PHP_7, PHP_8 // is_string() - PHP_4, PHP_5, PHP_7, PHP_8 // isset() - PHP_4, PHP_5, PHP_7, PHP_8 // print_r() - PHP_4, PHP_5, PHP_7, PHP_8 // serialize() - PHP_4, PHP_5, PHP_7, PHP_8 // settype() - PHP_4, PHP_5, PHP_7, PHP_8 // strval() - PHP_4, PHP_5, PHP_7, PHP_8 // unserialize() - PHP_4, PHP_5, PHP_7, PHP_8 // unset() - PHP_4, PHP_5, PHP_7, PHP_8 // var_dump() - PHP_4, PHP_5, PHP_7, PHP_8 // var_export() - PHP_4 >= PHP_4_2_0, PHP_5, PHP_7, PHP_8 // ============================== USING CLASSES (0) // ============================== USING DATA_TYPES (8) // bool // mixed // void // float // string // array // int // resource // ============================== END // REQUIREMENTS // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING // ============================== ABOUT // PHP Manual / Function Reference / Variable and Type Related Extensions / Variable handling // URL: https://www.php.net/manual/en/book.var.php // ============================== DESCRIPTION // VARIABLE_HANDLING // LANGUAGE_REFERENCE_TYPES_RESOURCES // // VARIABLE_HANDLING - BEGIN // Variable handling // // INTRODUCTION // INSTALLING_CONFIGURING // PREDEFINED_CONSTANTS // VARIABLE_HANDLING_FUNCTIONS // // INTRODUCTION - BEGIN // Introduction // // For information on how variables behave, see the Variables entry in the Language Reference section of the manual. // // LITERATURE_SOURCES // * PHP_NET (2023-09-23) // URL: https://www.php.net/manual/en/intro.var.php // INTRODUCTION - END // // INSTALLING_CONFIGURING - BEGIN // Installing/Configuring // // REQUIREMENTS // INSTALLATION // RUNTIME_CONFIGURATION // RESOURCE_TYPES // // REQUIREMENTS - BEGIN // Requirements // // No external libraries are needed to build this extension. // // LITERATURE_SOURCES // * PHP_NET (2023-09-23) // URL: https://www.php.net/manual/en/var.requirements.php // REQUIREMENTS - END // // INSTALLATION - BEGIN // Installation // // There is no installation needed to use these functions; they are part of the PHP core. // // LITERATURE_SOURCES // * PHP_NET (2023-09-23) // URL: https://www.php.net/manual/en/var.installation.php // INSTALLATION - END // // RUNTIME_CONFIGURATION - BEGIN // Runtime Configuration // // The behaviour of these functions is affected by settings in php.ini. // // Variables Configuration Options // Name | Default | Changeable | Changelog // unserialize_callback_func | null | PHP_INI_ALL | // unserialize_max_depth | "4096" | PHP_INI_ALL | Available as of PHP 7.4.0. // // For further details and definitions of the PHP_INI_* modes, see the Where a configuration setting may be set. // Here's a short explanation of the configuration directives. // // unserialize_callback_func string - The callback specified is called when unserialize() attempts to use an undefined class. A warning appears if the specified callback function is not defined, or if the callback function fails to define the missing class. // See also unserialize() and Autoloading Classes. // unserialize_max_depth int - The maximum depth of structures permitted during unserialization when using unserialize(), and is intended to prevent stack overflows. This can be disabled by setting unserialize_max_depth=0. // See also unserialize() and Autoloading Classes. // // LITERATURE_SOURCES // * PHP_NET (2023-09-23) // URL: https://www.php.net/manual/en/var.configuration.php // RUNTIME_CONFIGURATION - END // // RESOURCE_TYPES - BEGIN // Resource Types // // This extension has no resource types defined. // // LITERATURE_SOURCES // * PHP_NET (2023-09-23) // URL: https://www.php.net/manual/en/var.resources.php // RESOURCE_TYPES - END // // LITERATURE_SOURCES // * PHP_NET (2023-09-23) // URL: https://www.php.net/manual/en/var.setup.php // INSTALLING_CONFIGURING - END // // PREDEFINED_CONSTANTS - BEGIN // Predefined Constants // // This extension has no constants defined. // // LITERATURE_SOURCES // * PHP_NET (2023-09-23) // URL: https://www.php.net/manual/en/var.constants.php // PREDEFINED_CONSTANTS - END // // VARIABLE_HANDLING_FUNCTIONS - BEGIN // Variable handling Functions // // Table of Contents // * boolval - Get the boolean value of a variable // * debug_zval_dump - Dumps a string representation of an internal zval structure to output // * doubleval - Alias of floatval // * empty - Determine whether a variable is empty // * floatval - Get float value of a variable // * get_debug_type - Gets the type name of a variable in a way that is suitable for debugging // * get_defined_vars - Returns an array of all defined variables // * get_resource_id - Returns an integer identifier for the given resource // * get_resource_type - Returns the resource type // * gettype - Get the type of a variable // * intval - Get the integer value of a variable // * is_array - Finds whether a variable is an array // * is_bool - Finds out whether a variable is a boolean // * is_callable - Verify that a value can be called as a function from the current scope. // * is_countable - Verify that the contents of a variable is a countable value // * is_double - Alias of is_float // * is_float - Finds whether the type of a variable is float // * is_int - Find whether the type of a variable is integer // * is_integer - Alias of is_int // * is_iterable - Verify that the contents of a variable is an iterable value // * is_long - Alias of is_int // * is_null - Finds whether a variable is null // * is_numeric - Finds whether a variable is a number or a numeric string // * is_object - Finds whether a variable is an object // * is_real - Alias of is_float // * is_resource - Finds whether a variable is a resource // * is_scalar - Finds whether a variable is a scalar // * is_string - Find whether the type of a variable is string // * isset - Determine if a variable is declared and is different than null // * print_r - Prints human-readable information about a variable // * serialize - Generates a storable representation of a value // * settype - Set the type of a variable // * strval - Get string value of a variable // * unserialize - Creates a PHP value from a stored representation // * unset - Unset a given variable // * var_dump - Dumps information about a variable // * var_export - Outputs or returns a parsable string representation of a variable // // LITERATURE_SOURCES // * PHP_NET (2023-09-23) // URL: https://www.php.net/manual/en/ref.var.php // VARIABLE_HANDLING_FUNCTIONS - END // // LITERATURE_SOURCES // * PHP_NET (2023-09-23) // URL: https://www.php.net/manual/en/book.var.php // VARIABLE_HANDLING - END // // LANGUAGE_REFERENCE_TYPES_RESOURCES - BEGIN // Resources (PHP Manual / Language Reference / Types / 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. // See also the get_resource_type() function. // // Converting to resource // As resource variables hold special handles to opened files, database connections, image canvas areas and the like, converting to a resource makes no sense. // // Freeing resources // Thanks to the reference-counting system being part of 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. // Note: Persistent database links are an exception to this rule. They are not destroyed by the garbage collector. See the persistent connections section for more information. // // ===== LITERATURE_SOURCES // * PHP_NET (2023-09-22) // URL: https://www.php.net/manual/en/language.types.resource.php // LANGUAGE_REFERENCE_TYPES_RESOURCES - END // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_BOOLVAL // ============================== OFFLINE // ============================== ABOUT // Get the boolean value of a variable. // ============================== SUPPORT // PHP_5 - PHP_8 // ============================== USING FUNCTIONS (1) // boolval() - PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ============================== CODE /* function php_variable_variablehandling_boolval($value) { $return_boolval = false; // ========== BOOLVAL - BEGIN // ===== ABOUT // Get the boolean value of a variable // ===== DESCRIPTION // Returns the bool value of value. // ===== SUPPORTED // PHP_5 >= PHP_5_5_0, PHP_7, PHP_8 // ===== SYNTAX // boolval(mixed $value): bool // ===== CODE $return_boolval = boolval( $value // mixed value - The scalar value being converted to a bool. ); // Return Values // The bool value of value. // // [examples] // Examples // [example] // Example #1 boolval() examples // [php] // echo '0: '.(boolval(0) ? 'true' : 'false')."\n"; // echo '42: '.(boolval(42) ? 'true' : 'false')."\n"; // echo '0.0: '.(boolval(0.0) ? 'true' : 'false')."\n"; // echo '4.2: '.(boolval(4.2) ? 'true' : 'false')."\n"; // echo '"": '.(boolval("") ? 'true' : 'false')."\n"; // echo '"string": '.(boolval("string") ? 'true' : 'false')."\n"; // echo '"0": '.(boolval("0") ? 'true' : 'false')."\n"; // echo '"1": '.(boolval("1") ? 'true' : 'false')."\n"; // echo '[1, 2]: '.(boolval([1, 2]) ? 'true' : 'false')."\n"; // echo '[]: '.(boolval([]) ? 'true' : 'false')."\n"; // echo 'stdClass: '.(boolval(new stdClass) ? 'true' : 'false')."\n"; // [/php] // The above example will output: // [result] // 0: false // 42: true // 0.0: false // 4.2: true // "": false // "string": true // "0": false // "1": true // [1, 2]: true // []: false // stdClass: true // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-23) // URL: https://www.php.net/manual/en/function.boolval.php // ========== BOOLVAL - END // SYNTAX: // bool boolval(mixed $value) return $return_boolval; // bool } */ // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_BOOLVAL // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_DEBUG_ZVAL_DUMP // ============================== PUBLIC // ============================== ABOUT // Dumps a string representation of an internal zval structure to output. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // debug_zval_dump() - PHP_4 >= PHP_4_2_0, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_debug_zval_dump($value, $values) { // ========== DEBUG_ZVAL_DUMP - BEGIN // ===== ABOUT // Dumps a string representation of an internal zval structure to output // ===== DESCRIPTION // Dumps a string representation of an internal zval (Zend value) structure to output. This is mostly useful for understanding or debugging implementation details of the Zend Engine or PHP extensions. // ===== SUPPORTED // PHP_4 >= PHP_4_2_0, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // debug_zval_dump(mixed $value, mixed ...$values): void // ===== CODE debug_zval_dump( $value, // mixed value - The variable or value to dump. $values // mixed values - Further variables or values to dump. ); // Return Values // No value is returned. // // [examples] // Examples // [example] // Example #1 debug_zval_dump() example // [php] // $var1 = 'Hello'; // $var1 .= ' World'; // $var2 = $var1; // // debug_zval_dump($var1); // [/php] // The above example will output: // [result] // string(11) "Hello World" refcount(3) // [/result] // [/example] // [/examples] // Note: Understanding the refcount // The refcount value shown by this function may be surprising without a detailed understanding of the engine's implementation. // The Zend Engine uses reference counting for two different purposes: // * Optimizing memory usage using a technique called "copy on write", where multiple variables holding the same value point to the same copy in memory. When any of the variables is modified, it is pointed to a new copy in memory, and the reference count on the original is decreased by 1. // * Tracking variables which have been assigned or passed by reference (see References Explained). This refcount is stored on a separate reference zval, pointing to the zval for the current value. This additional zval is not currently shown by debug_zval_dump(). // Because debug_zval_dump() takes its input as normal parameters, passed by value, the copy on write technique will be used to pass them: rather than copying the data, the refcount will be increased by one for the lifetime of the function call. If the function modified the parameter after receiving it, then a copy would be made; since it does not, it will show a refcount one higher than in the calling scope. // The parameter passing also prevents debug_zval_dump() showing variables which have been assigned by reference. To illustrate, consider a slightly modified version of the above example: // [example] // [php] // $var1 = 'Hello'; // $var1 .= ' World'; // // Point three variables as references to the same value // $var2 =& $var1; // $var3 =& $var1; // // debug_zval_dump($var1); // [/php] // The above example will output: // [result] // string(11) "Hello World" refcount(2) // [/result] // Although $var1, $var2, and $var3 are linked as references, only the value is passed to debug_zval_dump(). That value is used once by the set of references, and once inside the debug_zval_dump(), so shows a refcount of 2. // [/example] // Further complications arise because of optimisations made in the engine for different data types. Some types such as integers do not use "copy on write", so do not show a refcount at all. In other cases, the refcount shows extra copies used internally, such as when a literal string or array is stored as part of a code instruction. // ===== LITERATURE_SOURCES // * PHP_NET (2023-09-22) // URL: https://www.php.net/manual/en/function.debug-zval-dump.php // ========== DEBUG_ZVAL_DUMP - END // SYNTAX: // void debug_zval_dump(mixed $value, mixed $values) // Return: void } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_DEBUG_ZVAL_DUMP // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_DOUBLEVAL // ============================== PUBLIC // ============================== ABOUT // Get float value of a variable. // // doubleval - Alias of floatval(). // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // doubleval() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_doubleval($value) { $return_doubleval = 0; // ========== DOUBLEVAL - BEGIN // ===== ABOUT // doubleval - Alias of floatval() // ===== DESCRIPTION // This function is an alias of: floatval(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // ===== CODE $return_doubleval = doubleval( $value // mixed $value ); // Return // float // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-23) // URL: https://www.php.net/manual/en/function.doubleval.php // ========== DOUBLEVAL - END // ========== FLOATVAL - BEGIN // ===== ABOUT // Get float value of a variable // ===== DESCRIPTION // Gets the float value of value. // ===== SUPPORTED // PHP_4 >= PHP_4_2_0, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // floatval(mixed $value): float // ===== CODE // $return_floatval = floatval( // $value // mixed value - May be any scalar type. floatval() should not be used on objects, as doing so will emit an E_WARNING level error and return 1. // ); // Return Values // The float value of the given variable. Empty arrays return 0, non-empty arrays return 1. // Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of float casting apply. // // Changelog // Version - Description // 8.0.0 - The error level when converting from object was changed from E_NOTICE to E_WARNING. // // [examples] // Examples // [example] // Example #1 floatval() Example // [php] // $var = '122.34343The'; // $float_value_of_var = floatval($var); // echo $float_value_of_var; // 122.34343 // [/php] // [/example] // [example] // Example #2 floatval() non-numeric leftmost characters Example // [php] // $var = 'The122.34343'; // $float_value_of_var = floatval($var); // echo $float_value_of_var; // 0 // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-23) // URL: https://www.php.net/manual/en/function.floatval.php // ========== FLOATVAL - END // SYNTAX: // float doubleval(mixed $value) return $return_doubleval; // float } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_DOUBLEVAL // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_EMPTY // ============================== PUBLIC // ============================== ABOUT // Determine whether a variable is empty. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // empty() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_empty($var) { $return_empty = false; // ========== EMPTY - BEGIN // ===== ABOUT // Determine whether a variable is empty // ===== DESCRIPTION // Determine whether a variable is considered to be empty. A variable is considered empty if it does not exist or if its value equals false. empty() does not generate a warning if the variable does not exist. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // empty(mixed $var): bool // ===== CODE $return_empty = empty( $var // mixed var - Variable to be checked // No warning is generated if the variable does not exist. That means empty() is essentially the concise equivalent to !isset($var) || $var == false. ); // Return Values // Returns true if var does not exist or has a value that is empty or equal to zero, aka falsey, see conversion to boolean. Otherwise returns false. // // [examples] // Examples // [example] // Example #1 A simple empty() / isset() comparison. // [php] // $var = 0; // // // Evaluates to true because $var is empty // if (empty($var)) { // echo '$var is either 0, empty, or not set at all'; // } // // // Evaluates as true because $var is set // if (isset($var)) { // echo '$var is set even though it is empty'; // } // [/php] // [/example] // [example] // Example #2 empty() on String Offsets // [php] // $expected_array_got_string = 'somestring'; // var_dump(empty($expected_array_got_string['some_key'])); // var_dump(empty($expected_array_got_string[0])); // var_dump(empty($expected_array_got_string['0'])); // var_dump(empty($expected_array_got_string[0.5])); // var_dump(empty($expected_array_got_string['0.5'])); // var_dump(empty($expected_array_got_string['0 Mostel'])); // [/php] // The above example will output: // [result] // bool(true) // bool(false) // bool(false) // bool(false) // bool(true) // bool(true) // [/result] // [/example] // [/examples] // // Notes // Note: Because this is a language construct and not a function, it cannot be called using variable functions, or named arguments. // Note: When using empty() on inaccessible object properties, the __isset() overloading method will be called, if declared. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-23) // URL: https://www.php.net/manual/en/function.empty.php // ========== EMPTY - END // SYNTAX: // bool empty(mixed $var) return $return_empty; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_EMPTY // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_FLOATVAL // ============================== PUBLIC // ============================== ABOUT // Get float value of a variable. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // floatval() - PHP_4 >= PHP_4_2_0, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_floatval($value) { $return_floatval = 0; // ========== FLOATVAL - BEGIN // ===== ABOUT // Get float value of a variable // ===== DESCRIPTION // Gets the float value of value. // ===== SUPPORTED // PHP_4 >= PHP_4_2_0, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // floatval(mixed $value): float // ===== CODE $return_floatval = floatval( $value // mixed value - May be any scalar type. floatval() should not be used on objects, as doing so will emit an E_WARNING level error and return 1. ); // Return Values // The float value of the given variable. Empty arrays return 0, non-empty arrays return 1. // Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of float casting apply. // // Changelog // Version - Description // 8.0.0 - The error level when converting from object was changed from E_NOTICE to E_WARNING. // // [examples] // Examples // [example] // Example #1 floatval() Example // [php] // $var = '122.34343The'; // $float_value_of_var = floatval($var); // echo $float_value_of_var; // 122.34343 // [/php] // [/example] // [example] // Example #2 floatval() non-numeric leftmost characters Example // [php] // $var = 'The122.34343'; // $float_value_of_var = floatval($var); // echo $float_value_of_var; // 0 // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-23) // URL: https://www.php.net/manual/en/function.floatval.php // ========== FLOATVAL - END // SYNTAX: // float floatval(mixed $value) return $return_floatval; // float } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_FLOATVAL // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_GET_DEBUG_TYPE // ============================== OFFLINE // ============================== ABOUT // Gets the type name of a variable in a way that is suitable for debugging. // ============================== SUPPORT // PHP_8 // ============================== USING FUNCTIONS (1) // get_debug_type() - PHP_8 // ============================== CODE /* function php_variable_variablehandling_get_debug_type($value) { $return_get_debug_type = null; // ========== GET_DEBUG_TYPE - BEGIN // ===== ABOUT // Gets the type name of a variable in a way that is suitable for debugging // ===== DESCRIPTION // Returns the resolved name of the PHP variable value. This function will resolve objects to their class name, resources to their resource type name, and scalar values to their common name as would be used in type declarations. // This function differs from gettype() in that it returns type names that are more consistent with actual usage, rather than those present for historical reasons. // ===== SUPPORTED // PHP_8 // ===== SYNTAX // get_debug_type(mixed $value): string // ===== CODE $return_get_debug_type = get_debug_type( $value // mixed value - The variable being type checked. ); // Return Values // Possible values for the returned string are: // Type + State | Return Value | Notes // null | "null" | - // Booleans (true or false) | "bool" | - // Integers | "int" | - // Floats | "float" | - // Strings | "string" | - // Arrays | "array" | - // Resources | "resource (resourcename)" | - // Resources (Closed) | "resource (closed)" | Example: A file stream after being closed with fclose. // Objects from Named Classes | The full name of the class including its namespace e.g. Foo\Bar | - // Objects from Anonymous Classes | "class@anonymous" | Anonymous classes are those created through the $x = new class { ... } syntax // // [examples] // Examples // [example] // Example #1 get_debug_type() example // [php] // echo get_debug_type(null) . PHP_EOL; // echo get_debug_type(true) . PHP_EOL; // echo get_debug_type(1) . PHP_EOL; // echo get_debug_type(0.1) . PHP_EOL; // echo get_debug_type("foo") . PHP_EOL; // echo get_debug_type([]) . PHP_EOL; // // $fp = fopen(__FILE__, 'rb'); // echo get_debug_type($fp) . PHP_EOL; // // fclose($fp); // echo get_debug_type($fp) . PHP_EOL; // // echo get_debug_type(new stdClass) . PHP_EOL; // echo get_debug_type(new class {}) . PHP_EOL; // [/php] // The above example will output something similar to: // [result] // null // bool // int // float // string // array // resource (stream) // resource (closed) // stdClass // class@anonymous // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-23) // URL: https://www.php.net/manual/en/function.get-debug-type.php // ========== GET_DEBUG_TYPE - END // SYNTAX: // string get_debug_type(mixed $value) return $return_get_debug_type; // string } */ // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_GET_DEBUG_TYPE // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_GET_DEFINED_VARS // ============================== PUBLIC // ============================== ABOUT // Returns an array of all defined variables. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // get_defined_vars() - PHP_4 >= PHP_4_0_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_get_defined_vars() { $return_get_defined_vars = null; // ========== GET_DEFINED_VARS - BEGIN // ===== ABOUT // Returns an array of all defined variables // ===== DESCRIPTION // This function returns a multidimensional array containing a list of all defined variables, be them environment, server or user-defined variables, within the scope that get_defined_vars() is called. // ===== SUPPORTED // PHP_4 >= PHP_4_0_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // get_defined_vars(): array // ===== CODE $return_get_defined_vars = get_defined_vars( // This function has no parameters. ); // Return Values // A multidimensional array with all the variables. // // [examples] // Examples // [example] // Example #1 get_defined_vars() Example // [php] // $b = array(1, 1, 2, 3, 5, 8); // // $arr = get_defined_vars(); // // // print $b // print_r($arr["b"]); // // // print path to the PHP interpreter (if used as a CGI) // // e.g. /usr/local/bin/php // echo $arr["_"]; // // // print the command-line parameters if any // print_r($arr["argv"]); // // // print all the server vars // print_r($arr["_SERVER"]); // // // print all the available keys for the arrays of variables // print_r(array_keys(get_defined_vars())); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.get-defined-vars.php // ========== GET_DEFINED_VARS - END // SYNTAX: // array get_defined_vars() return $return_get_defined_vars; // array } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_GET_DEFINED_VARS // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_GET_RESOURCE_ID // ============================== OFFLINE // ============================== ABOUT // Returns an integer identifier for the given resource. // ============================== SUPPORT // PHP_8 // ============================== USING FUNCTIONS (1) // get_resource_id() - PHP_8 // ============================== CODE /* function php_variable_variablehandling_get_resource_id($resource) { $return_get_resource_id = 0; // ========== GET_RESOURCE_ID - BEGIN // ===== ABOUT // Returns an integer identifier for the given resource // ===== DESCRIPTION // This function provides a type-safe way for generating the integer identifier for a resource. // ===== SUPPORTED // PHP_8 // ===== SYNTAX // get_resource_id(resource $resource): int // ===== CODE $return_get_resource_id = get_resource_id( $resource // resource resource - The evaluated resource handle. ); // Return Values // The int identifier for the given resource. // This function is essentially an int cast of resource to make it easier to retrieve the resource ID. // // [examples] // Examples // [example] // Example #1 get_resource_id() produces the same result as an int cast // [php] // $handle = fopen("php://stdout", "w"); // // echo (int) $handle . "\n"; // // echo get_resource_id($handle); // // [/php] // The above example will output something similar to: // [result] // 698 // 698 // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.get-resource-id.php // ========== GET_RESOURCE_ID - END // SYNTAX: // int get_resource_id(resource $resource) return $return_get_resource_id; // int } */ // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_GET_RESOURCE_ID // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_GET_RESOURCE_TYPE // ============================== PUBLIC // ============================== ABOUT // Returns the resource type. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // get_resource_type() - PHP_4 >= PHP_4_0_2, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_get_resource_type($resource) { $return_get_resource_type = null; // ========== GET_RESOURCE_TYPE - BEGIN // ===== ABOUT // Returns the resource type // ===== DESCRIPTION // This function gets the type of the given resource. // ===== SUPPORTED // PHP_4 >= PHP_4_0_2, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // get_resource_type(resource $resource): string // ===== CODE $return_get_resource_type = get_resource_type( $resource // resource resource - The evaluated resource handle. ); // Return Values // If the given resource is a resource, this function will return a string representing its type. If the type is not identified by this function, the return value will be the string Unknown. // This function will return null and generate an error if resource is not a resource. // // [examples] // Examples // [example] // Example #1 get_resource_type() example // [php] // $fp = fopen("foo", "w"); // echo get_resource_type($fp) . "\n"; // // // As of PHP 8.0.0, the following does not work anymore. The curl_init function returns a CurlHandle object now. // $c = curl_init(); // echo get_resource_type($c) . "\n"; // [/php] // Output of the above example in PHP 7: // [result] // stream // curl // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.get-resource-type.php // ========== GET_RESOURCE_TYPE - END // SYNTAX: // string get_resource_type(resource $resource) return $return_get_resource_type; // string } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_GET_RESOURCE_TYPE // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_GETTYPE // ============================== PUBLIC // ============================== ABOUT // Get the type of a variable. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // gettype() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_gettype($value) { $return_gettype = null; // ========== GETTYPE - BEGIN // ===== ABOUT // Get the type of a variable // ===== DESCRIPTION // Returns the type of the PHP variable value. For type checking, use is_* functions. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // gettype(mixed $value): string // ===== CODE $return_gettype = gettype( $value // mixed value - The variable being type checked. ); // Return Values // Possible values for the returned string are: // * "boolean" // * "integer" // * "double" (for historical reasons "double" is returned in case of a float, and not simply "float") // * "string" // * "array" // * "object" // * "resource" // * "resource (closed)" as of PHP 7.2.0 // * "NULL" // * "unknown type" // // Changelog // Version - Description // 7.2.0 - Closed resources are now reported as 'resource (closed)'. Previously the returned value for closed resources were 'unknown type'. // // [examples] // Examples // [example] // Example #1 gettype() example // [php] // // $data = array(1, 1., NULL, new stdClass, 'foo'); // // foreach ($data as $value) { // echo gettype($value), "\n"; // } // // [/php] // The above example will output something similar to: // [result] // integer // double // NULL // object // string // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.gettype.php // ========== GETTYPE - END // SYNTAX: // string gettype(mixed $value) return $return_gettype; // string } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_GETTYPE // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_INTVAL // ============================== PUBLIC // ============================== ABOUT // Get the integer value of a variable. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // intval() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_intval($value, $base = 10) { $return_intval = 0; // ========== INTVAL - BEGIN // ===== ABOUT // Get the integer value of a variable // ===== DESCRIPTION // Returns the int value of value, using the specified base for the conversion (the default is base 10). intval() should not be used on objects, as doing so will emit an E_WARNING level error and return 1. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // intval(mixed $value, int $base = 10): int // ===== CODE $return_intval = intval( $value, // mixed value - The scalar value being converted to an integer $base // int base - The base for the conversion // Note: // If base is 0, the base used is determined by the format of value: // * if string includes a "0x" (or "0X") prefix, the base is taken as 16 (hex); otherwise, // * if string starts with a "0b" (or "0B"), the base is taken as 2 (binary); otherwise, // * if string starts with "0", the base is taken as 8 (octal); otherwise, // * the base is taken as 10 (decimal). ); // Return Values // The integer value of value on success, or 0 on failure. Empty arrays return 0, non-empty arrays return 1. // The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807. // Strings will most likely return 0 although this depends on the leftmost characters of the string. The common rules of integer casting apply. // // Changelog // Version - Description // 8.0.0 - The error level when converting from object was changed from E_NOTICE to E_WARNING. // // [examples] // Examples // [example] // Example #1 intval() examples // The following examples are based on a 64 bit system. // [php] // echo intval(42); // 42 // echo intval(4.2); // 4 // echo intval('42'); // 42 // echo intval('+42'); // 42 // echo intval('-42'); // -42 // echo intval(042); // 34 // echo intval('042'); // 42 // echo intval(1e10); // 10000000000 // echo intval('1e10'); // 10000000000 // echo intval(0x1A); // 26 // echo intval('0x1A'); // 0 // echo intval('0x1A', 0); // 26 // echo intval(42000000); // 42000000 // echo intval(420000000000000000000); // -4275113695319687168 // echo intval('420000000000000000000'); // 9223372036854775807 // echo intval(42, 8); // 42 // echo intval('42', 8); // 34 // echo intval(array()); // 0 // echo intval(array('foo', 'bar')); // 1 // echo intval(false); // 0 // echo intval(true); // 1 // [/php] // [/example] // [/examples] // // Notes // Note: The base parameter has no effect unless the value parameter is a string. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.intval.php // ========== INTVAL - END // SYNTAX: // int intval(mixed $value, int $base = 10) return $return_intval; // int } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_INTVAL // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_ARRAY // ============================== PUBLIC // ============================== ABOUT // Finds whether a variable is an array. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_array() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_array($value) { $return_is_array = false; // ========== IS_ARRAY - BEGIN // ===== ABOUT // Finds whether a variable is an array // ===== DESCRIPTION // Finds whether the given variable is an array. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_array(mixed $value): bool // ===== CODE $return_is_array = is_array( $value // mixed value - The variable being evaluated. ); // Return Values // Returns true if value is an array, false otherwise. // // [examples] // Examples // [example] // Example #1 Check that variable is an array // [php] // $yes = array('this', 'is', 'an array'); // // echo is_array($yes) ? 'Array' : 'not an Array'; // echo "\n"; // // $no = 'this is a string'; // // echo is_array($no) ? 'Array' : 'not an Array'; // [/php] // The above example will output: // [result] // Array // not an Array // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-array.php // ========== IS_ARRAY - END // SYNTAX: // bool is_array(mixed $value) return $return_is_array; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_ARRAY // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_BOOL // ============================== PUBLIC // ============================== ABOUT // Finds out whether a variable is a boolean. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_bool() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_bool($value) { $return_is_bool = false; // ========== IS_BOOL - BEGIN // ===== ABOUT // Finds out whether a variable is a boolean // ===== DESCRIPTION // Finds whether the given variable is a boolean. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_bool(mixed $value): bool // ===== CODE $return_is_bool = is_bool( $value // mixed value - The variable being evaluated. ); // Return Values // Returns true if value is a bool, false otherwise. // // [examples] // Examples // [example] // Example #1 is_bool() examples // [php] // $a = false; // $b = 0; // // // Since $a is a boolean, it will return true // if (is_bool($a) === true) { // echo "Yes, this is a boolean"; // } // // // Since $b is not a boolean, it will return false // if (is_bool($b) === false) { // echo "No, this is not a boolean"; // } // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-23) // URL: https://www.php.net/manual/en/function.is-bool.php // ========== IS_BOOL - END // SYNTAX: // bool is_bool(mixed $value) return $return_is_bool; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_BOOL // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_CALLABLE // ============================== PUBLIC // ============================== ABOUT // Verify that a value can be called as a function from the current scope. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_callable() - PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_callable($value, $syntax_only = false, & $callable_name) { $return_is_callable = false; // ========== IS_CALLABLE - BEGIN // ===== ABOUT // Verify that a value can be called as a function from the current scope. // ===== DESCRIPTION // Verify that a value is a callable. // ===== SUPPORTED // PHP_4 >= PHP_4_0_6, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_callable(mixed $value, bool $syntax_only = false, string &$callable_name = null): bool // ===== CODE $return_is_callable = is_callable( $value, // mixed value - The value to check $syntax_only, // bool syntax_only - If set to true the function only verifies that value might be a function or method. It will only reject simple variables that are not strings, or an array that does not have a valid structure to be used as a callback. The valid ones are supposed to have only 2 entries, the first of which is an object or a string, and the second a string. $callable_name // string& callable_name - Receives the "callable name". In the example below it is "someClass::someMethod". Note, however, that despite the implication that someClass::SomeMethod() is a callable static method, this is not the case. ); // Return Values // Returns true if value is callable, false otherwise. // // [examples] // Examples // [example] // Example #1 is_callable() example // [php] // // How to check a variable to see if it can be called // // as a function. // // // // // Simple variable containing a function // // // // function someFunction() // { // } // // $functionVariable = 'someFunction'; // // var_dump(is_callable($functionVariable, false, $callable_name)); // bool(true) // // echo $callable_name, "\n"; // someFunction // // // // // Array containing a method // // // // class someClass { // // function someMethod() // { // } // // } // // $anObject = new someClass(); // // $methodVariable = array($anObject, 'someMethod'); // // var_dump(is_callable($methodVariable, true, $callable_name)); // bool(true) // // echo $callable_name, "\n"; // someClass::someMethod // // [/php] // [/example] // [example] // Example #2 is_callable() and constructors // is_callable() reports constructors as not being callable. // [php] // // class Foo // { // public function __construct() {} // public function foo() {} // } // // var_dump( // is_callable(array('Foo', '__construct')), // is_callable(array('Foo', 'foo')) // ); // [/php] // The above example will output: // [result] // bool(false) // bool(false) // [/result] // [/example] // [/examples] // // Notes // * An object is always callable if it implements __invoke(), and that method is visible in the current scope. // * A class name is callable if it implements __callStatic(). // * If an object implements __call(), then this function will return true for any method on that object, even if the method is not defined. // * This function may trigger autoloading if called with the name of a class. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-callable.php // ========== IS_CALLABLE - END // SYNTAX: // bool is_callable(mixed $value, bool $syntax_only = false, string& $callable_name) return $return_is_callable; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_CALLABLE // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_COUNTABLE // ============================== OFFLINE // ============================== ABOUT // Verify that the contents of a variable is a countable value. // ============================== SUPPORT // PHP_7 - PHP_8 // ============================== USING FUNCTIONS (1) // is_countable() - PHP_7 >= PHP_7_3_0, PHP_8 // ============================== CODE /* function php_variable_variablehandling_is_countable($value) { $return_is_countable = false; // ========== IS_COUNTABLE - BEGIN // ===== ABOUT // Verify that the contents of a variable is a countable value // ===== DESCRIPTION // Verify that the contents of a variable is an array or an object implementing Countable // ===== SUPPORTED // PHP_7 >= PHP_7_3_0, PHP_8 // ===== SYNTAX // is_countable(mixed $value): bool // ===== CODE $return_is_countable = is_countable( $value // mixed value - The value to check ); // Return Values // Returns true if value is countable, false otherwise. // // Changelog // Version - Description // 7.3.0 - is_countable() has been added. // // [examples] // Examples // [example] // Example #1 is_countable() examples // [php] // var_dump(is_countable([1, 2, 3])); // bool(true) // var_dump(is_countable(new ArrayIterator(['foo', 'bar', 'baz']))); // bool(true) // var_dump(is_countable(new ArrayIterator())); // bool(true) // var_dump(is_countable(new stdClass())); // bool(false) // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-countable.php // ========== IS_COUNTABLE - END // SYNTAX: // bool is_countable(mixed $value) return $return_is_countable; // bool } */ // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_COUNTABLE // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_DOUBLE // ============================== PUBLIC // ============================== ABOUT // Finds whether the type of a variable is float. // // is_double - Alias of is_float(). // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_double() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_double($value) { $return_is_double = false; // ========== IS_DOUBLE - BEGIN // ===== ABOUT // is_double - Alias of is_float() // ===== DESCRIPTION // This function is an alias of: is_float(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // ===== CODE $return_is_double = is_double( $value // mixed value - The variable being evaluated. ); // Return // bool // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-23) // URL: https://www.php.net/manual/en/function.is-double.php // ========== IS_DOUBLE - END // ========== IS_FLOAT - BEGIN // ===== ABOUT // Finds whether the type of a variable is float // ===== DESCRIPTION // Finds whether the type of the given variable is float. // Note: To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_float(mixed $value): bool // ===== CODE // $return_is_float = is_float( // $value // mixed value - The variable being evaluated. // ); // Return Values // Returns true if value is a float, false otherwise. // // [examples] // Examples // [example] // Example #1 is_float() example // [php] // // var_dump(is_float(27.25)); // var_dump(is_float('abc')); // var_dump(is_float(23)); // var_dump(is_float(23.5)); // var_dump(is_float(1e7)); //Scientific Notation // var_dump(is_float(true)); // [/php] // The above example will output: // [result] // bool(true) // bool(false) // bool(false) // bool(true) // bool(true) // bool(false) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-23) // URL: https://www.php.net/manual/en/function.is-float.php // ========== IS_FLOAT - END // SYNTAX: // bool is_double(mixed $value) return $return_is_double; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_DOUBLE // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_FLOAT // ============================== PUBLIC // ============================== ABOUT // Finds whether the type of a variable is float. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_float() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_float($value) { $return_is_float = false; // ========== IS_FLOAT - BEGIN // ===== ABOUT // Finds whether the type of a variable is float // ===== DESCRIPTION // Finds whether the type of the given variable is float. // Note: To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_float(mixed $value): bool // ===== CODE $return_is_float = is_float( $value // mixed value - The variable being evaluated. ); // Return Values // Returns true if value is a float, false otherwise. // // [examples] // Examples // [example] // Example #1 is_float() example // [php] // // var_dump(is_float(27.25)); // var_dump(is_float('abc')); // var_dump(is_float(23)); // var_dump(is_float(23.5)); // var_dump(is_float(1e7)); //Scientific Notation // var_dump(is_float(true)); // [/php] // The above example will output: // [result] // bool(true) // bool(false) // bool(false) // bool(true) // bool(true) // bool(false) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-23) // URL: https://www.php.net/manual/en/function.is-float.php // ========== IS_FLOAT - END // SYNTAX: // bool is_float(mixed $value) return $return_is_float; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_FLOAT // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_INT // ============================== PUBLIC // ============================== ABOUT // Find whether the type of a variable is integer. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_int() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_int($value) { $return_is_int = false; // ========== IS_INT - BEGIN // ===== ABOUT // Find whether the type of a variable is integer // ===== DESCRIPTION // Finds whether the type of the given variable is integer. // Note: To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_int(mixed $value): bool // ===== CODE $return_is_int = is_int( $value // mixed value - The variable being evaluated. ); // Return Values // Returns true if value is an int, false otherwise. // // [examples] // Examples // [example] // Example #1 is_int() example // [php] // $values = array(23, "23", 23.5, "23.5", null, true, false); // foreach ($values as $value) { // echo "is_int("; // var_export($value); // echo ") = "; // var_dump(is_int($value)); // } // [/php] // The above example will output: // [result] // is_int(23) = bool(true) // is_int('23') = bool(false) // is_int(23.5) = bool(false) // is_int('23.5') = bool(false) // is_int(NULL) = bool(false) // is_int(true) = bool(false) // is_int(false) = bool(false) // // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-int.php // ========== IS_INT - END // SYNTAX: // bool is_int(mixed $value) return $return_is_int; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_INT // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_INTEGER // ============================== PUBLIC // ============================== ABOUT // Find whether the type of a variable is integer. // // is_integer - Alias of is_int(). // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_integer() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_integer($value) { $return_is_integer = false; // ========== IS_INTEGER - BEGIN // ===== ABOUT // is_integer - Alias of is_int() // ===== DESCRIPTION // This function is an alias of: is_int(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // ===== CODE $return_is_integer = is_integer( $value // mixed value ); // Return // bool // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-integer.php // ========== IS_INTEGER - END // ========== IS_INT - BEGIN // ===== ABOUT // Find whether the type of a variable is integer // ===== DESCRIPTION // Finds whether the type of the given variable is integer. // Note: To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_int(mixed $value): bool // ===== CODE $return_is_int = is_int( $value // mixed value - The variable being evaluated. ); // Return Values // Returns true if value is an int, false otherwise. // // [examples] // Examples // [example] // Example #1 is_int() example // [php] // $values = array(23, "23", 23.5, "23.5", null, true, false); // foreach ($values as $value) { // echo "is_int("; // var_export($value); // echo ") = "; // var_dump(is_int($value)); // } // [/php] // The above example will output: // [result] // is_int(23) = bool(true) // is_int('23') = bool(false) // is_int(23.5) = bool(false) // is_int('23.5') = bool(false) // is_int(NULL) = bool(false) // is_int(true) = bool(false) // is_int(false) = bool(false) // // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-int.php // ========== IS_INT - END // SYNTAX: // bool is_integer(mixed $value) return $return_is_integer; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_INTEGER // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_ITERABLE // ============================== OFFLINE // ============================== ABOUT // Verify that the contents of a variable is an iterable value. // ============================== SUPPORT // PHP_7 - PHP_8 // ============================== USING FUNCTIONS (1) // is_iterable() - PHP_7 >= PHP_7_1_0, PHP_8 // ============================== CODE /* function php_variable_variablehandling_is_iterable($value) { $return_is_iterable = false; // ========== IS_ITERABLE - BEGIN // ===== ABOUT // Verify that the contents of a variable is an iterable value // ===== DESCRIPTION // Verify that the contents of a variable is accepted by the iterable pseudo-type, i.e. that it is either an array or an object implementing Traversable // ===== SUPPORTED // PHP_7 >= PHP_7_1_0, PHP_8 // ===== SYNTAX // is_iterable(mixed $value): bool // ===== CODE $return_is_iterable = is_iterable( $value // mixed value - The value to check ); // Return Values // Returns true if value is iterable, false otherwise. // // [examples] // Examples // [example] // Example #1 is_iterable() examples // [php] // // var_dump(is_iterable([1, 2, 3])); // bool(true) // var_dump(is_iterable(new ArrayIterator([1, 2, 3]))); // bool(true) // var_dump(is_iterable((function () { yield 1; })())); // bool(true) // var_dump(is_iterable(1)); // bool(false) // var_dump(is_iterable(new stdClass())); // bool(false) // // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-iterable.php // ========== IS_ITERABLE - END // SYNTAX: // bool is_iterable(mixed $value) return $return_is_iterable; // bool } */ // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_ITERABLE // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_LONG // ============================== PUBLIC // ============================== ABOUT // Find whether the type of a variable is integer. // // is_long - Alias of is_int(). // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_long() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_long($value) { $return_is_long = false; // ========== IS_LONG - BEGIN // ===== ABOUT // is_long - Alias of is_int() // ===== DESCRIPTION // This function is an alias of: is_int(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // ===== CODE $return_is_long = is_long( $value // mixed value - The variable being evaluated. ); // Return // bool // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-long.php // ========== IS_LONG - END // ========== IS_INT - BEGIN // ===== ABOUT // Find whether the type of a variable is integer // ===== DESCRIPTION // Finds whether the type of the given variable is integer. // Note: To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_int(mixed $value): bool // ===== CODE // $return_is_int = is_int( // // $value // mixed value - The variable being evaluated. // // ); // Return Values // Returns true if value is an int, false otherwise. // // [examples] // Examples // [example] // Example #1 is_int() example // [php] // $values = array(23, "23", 23.5, "23.5", null, true, false); // foreach ($values as $value) { // echo "is_int("; // var_export($value); // echo ") = "; // var_dump(is_int($value)); // } // [/php] // The above example will output: // [result] // is_int(23) = bool(true) // is_int('23') = bool(false) // is_int(23.5) = bool(false) // is_int('23.5') = bool(false) // is_int(NULL) = bool(false) // is_int(true) = bool(false) // is_int(false) = bool(false) // // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-int.php // ========== IS_INT - END // SYNTAX: // bool is_long(mixed $value) return $return_is_long; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_LONG // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_NULL // ============================== PUBLIC // ============================== ABOUT // Finds whether a variable is null. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_null() - PHP_4 >= PHP_4_0_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_null($value) { $return_is_null = false; // ========== IS_NULL - BEGIN // ===== ABOUT // Finds whether a variable is null // ===== DESCRIPTION // Finds whether the given variable is null. // ===== SUPPORTED // PHP_4 >= PHP_4_0_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_null(mixed $value): bool // ===== CODE $return_is_null = is_null( $value // mixed value - The variable being evaluated. ); // Return Values // Returns true if value is null, false otherwise. // // [examples] // Examples // [example] // Example #1 is_null() example // [php] // // error_reporting(E_ALL); // // $foo = NULL; // var_dump(is_null($inexistent), is_null($foo)); // // [/php] // // [result] // Notice: Undefined variable: inexistent in ... // bool(true) // bool(true) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-null.php // ========== IS_NULL - END // SYNTAX: // bool is_null(mixed $value) return $return_is_null; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_NULL // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_NUMERIC // ============================== PUBLIC // ============================== ABOUT // Finds whether a variable is a number or a numeric string. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_numeric() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_numeric($value) { $return_is_numeric = false; // ========== IS_NUMERIC - BEGIN // ===== ABOUT // Finds whether a variable is a number or a numeric string // ===== DESCRIPTION // Determines if the given variable is a number or a numeric string. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_numeric(mixed $value): bool // ===== CODE $return_is_numeric = is_numeric( $value // mixed value - The variable being evaluated. ); // Return Values // Returns true if value is a number or a numeric string, false otherwise. // // Changelog // Version - Description // 8.0.0 - Numeric strings ending with whitespace ("42 ") will now return true. Previously, false was returned instead. // // [examples] // Examples // [example] // Example #1 is_numeric() examples // [php] // $tests = array( // "42", // 1337, // 0x539, // 02471, // 0b10100111001, // 1337e0, // "0x539", // "02471", // "0b10100111001", // "1337e0", // "not numeric", // array(), // 9.1, // null, // '', // ); // // foreach ($tests as $element) { // if (is_numeric($element)) { // echo var_export($element, true) . " is numeric", PHP_EOL; // } else { // echo var_export($element, true) . " is NOT numeric", PHP_EOL; // } // } // [/php] // The above example will output: // [result] // '42' is numeric // 1337 is numeric // 1337 is numeric // 1337 is numeric // 1337 is numeric // 1337.0 is numeric // '0x539' is NOT numeric // '02471' is numeric // '0b10100111001' is NOT numeric // '1337e0' is numeric // 'not numeric' is NOT numeric // array ( // ) is NOT numeric // 9.1 is numeric // NULL is NOT numeric // '' is NOT numeric // [/result] // [/example] // [example] // Example #2 is_numeric() with whitespace // [php] // $tests = [ // " 42", // "42 ", // "\u{A0}9001", // non-breaking space // "9001\u{A0}", // non-breaking space // ]; // // foreach ($tests as $element) { // if (is_numeric($element)) { // echo var_export($element, true) . " is numeric", PHP_EOL; // } else { // echo var_export($element, true) . " is NOT numeric", PHP_EOL; // } // } // [/php] // Output of the above example in PHP 8: // [result] // ' 42' is numeric // '42 ' is numeric // ' 9001' is NOT numeric // '9001 ' is NOT numeric // [/result] // Output of the above example in PHP 7: // [result] // ' 42' is numeric // '42 ' is NOT numeric // ' 9001' is NOT numeric // '9001 ' is NOT numeric // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-numeric.php // ========== IS_NUMERIC - END // SYNTAX: // bool is_numeric(mixed $value) return $return_is_numeric; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_NUMERIC // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_OBJECT // ============================== PUBLIC // ============================== ABOUT // Finds whether a variable is an object. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_object() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_object($value) { $return_is_object = false; // ========== IS_OBJECT - BEGIN // ===== ABOUT // Finds whether a variable is an object // ===== DESCRIPTION // Finds whether the given variable is an object. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_object(mixed $value): bool // ===== CODE $return_is_object = is_object( $value // mixed value - The variable being evaluated. ); // Return Values // Returns true if value is an object, false otherwise. // // Changelog // Version - Description // 7.2.0 - is_object() now returns true for unserialized objects without a class definition (class of __PHP_Incomplete_Class). Previously false was returned. // // [examples] // Examples // [example] // Example #1 is_object() example // [php] // // Declare a simple function to return an // // array from our object // function get_students($obj) // { // if (!is_object($obj)) { // return false; // } // // return $obj->students; // } // // // Declare a new class instance and fill up // // some values // $obj = new stdClass(); // $obj->students = array('Kalle', 'Ross', 'Felipe'); // // var_dump(get_students(null)); // var_dump(get_students($obj)); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-object.php // ========== IS_OBJECT - END // SYNTAX: // bool is_object(mixed $value) return $return_is_object; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_OBJECT // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_REAL // ============================== PUBLIC // ============================== ABOUT // Finds whether the type of a variable is float. // // is_real - Alias of is_float(). // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_real() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_real($value) { $return_is_real = false; // ========== IS_REAL - BEGIN // ===== ABOUT // is_real - Alias of is_float() // ===== DESCRIPTION // This function is an alias of: is_float(). // Warning: This alias was DEPRECATED in PHP 7.4.0, and REMOVED as of PHP 8.0.0. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // ===== CODE $return_is_real = is_real( $value // mixed value ); // Return // bool // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-real.php // ========== IS_REAL - END // ========== IS_FLOAT - BEGIN // ===== ABOUT // Finds whether the type of a variable is float // ===== DESCRIPTION // Finds whether the type of the given variable is float. // Note: To test if a variable is a number or a numeric string (such as form input, which is always a string), you must use is_numeric(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_float(mixed $value): bool // ===== CODE // $return_is_float = is_float( // $value // mixed value - The variable being evaluated. // ); // Return Values // Returns true if value is a float, false otherwise. // // [examples] // Examples // [example] // Example #1 is_float() example // [php] // // var_dump(is_float(27.25)); // var_dump(is_float('abc')); // var_dump(is_float(23)); // var_dump(is_float(23.5)); // var_dump(is_float(1e7)); //Scientific Notation // var_dump(is_float(true)); // [/php] // The above example will output: // [result] // bool(true) // bool(false) // bool(false) // bool(true) // bool(true) // bool(false) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-float.php // ========== IS_FLOAT - END // SYNTAX: // bool is_real(mixed $value) return $return_is_real; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_REAL // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_RESOURCE // ============================== PUBLIC // ============================== ABOUT // Finds whether a variable is a resource. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_resource() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_resource($value) { $return_is_resource = false; // ========== IS_RESOURCE - BEGIN // ===== ABOUT // Finds whether a variable is a resource // ===== DESCRIPTION // Finds whether the given variable is a resource. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_resource(mixed $value): bool // ===== CODE $return_is_resource = is_resource( $value // mixed value - The variable being evaluated. ); // Return Values // Returns true if value is a resource, false otherwise. // // [examples] // Examples // [example] // Example #1 is_resource() example // [php] // // $handle = fopen("php://stdout", "w"); // if (is_resource($handle)) { // echo '$handle is a resource'; // } // // [/php] // The above example will output: // [result] // $handle is a resource // [/result] // [/example] // [/examples] // // Notes // Note: is_resource() is not a strict type-checking method: it will return false if value is a resource variable that has been closed. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-resource.php // ========== IS_RESOURCE - END // SYNTAX: // bool is_resource(mixed $value) return $return_is_resource; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_RESOURCE // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_SCALAR // ============================== PUBLIC // ============================== ABOUT // Finds whether a variable is a scalar // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_scalar() - PHP_4 >= PHP_4_0_5, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_scalar($value) { $return_is_scalar = false; // ========== IS_SCALAR - BEGIN // ===== ABOUT // Finds whether a variable is a scalar // ===== DESCRIPTION // Finds whether the given variable is a scalar. // Scalar variables are those containing an int, float, string or bool. Types array, object, resource and null are not scalar. // Note: is_scalar() does not consider resource type values to be scalar as resources are abstract datatypes which are currently based on integers. This implementation detail should not be relied upon, as it may change. // Note: is_scalar() does not consider NULL to be scalar. // ===== SUPPORTED // PHP_4 >= PHP_4_0_5, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_scalar(mixed $value): bool // ===== CODE $return_is_scalar = is_scalar( $value // mixed $value - The variable being evaluated. ); // Return Values // Returns true if value is a scalar, false otherwise. // // [examples] // Examples // [example] // Example #1 is_scalar() example // [php] // function show_var($var) // { // if (is_scalar($var)) { // echo $var; // } else { // var_dump($var); // } // } // $pi = 3.1416; // $proteins = array("hemoglobin", "cytochrome c oxidase", "ferredoxin"); // // show_var($pi); // show_var($proteins) // // [/php] // The above example will output: // [result] // 3.1416 // array(3) { // [0]=> // string(10) "hemoglobin" // [1]=> // string(20) "cytochrome c oxidase" // [2]=> // string(10) "ferredoxin" // } // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-scalar.php // ========== IS_SCALAR - END // SYNTAX: // bool is_scalar(mixed $value) return $return_is_scalar; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_SCALAR // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_IS_STRING // ============================== PUBLIC // ============================== ABOUT // Find whether the type of a variable is string. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // is_string() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_is_string($value) { $return_is_string = false; // ========== IS_STRING - BEGIN // ===== ABOUT // Find whether the type of a variable is string // ===== DESCRIPTION // Finds whether the type of the given variable is string. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // is_string(mixed $value): bool // ===== CODE $return_is_string = is_string( $value // mixed value - The variable being evaluated. ); // Return Values // Returns true if value is of type string, false otherwise. // // [examples] // Examples // [example] // Example #1 is_string() example // [php] // $values = array(false, true, null, 'abc', '23', 23, '23.5', 23.5, '', ' ', '0', 0); // foreach ($values as $value) { // echo "is_string("; // var_export($value); // echo ") = "; // echo var_dump(is_string($value)); // } // [/php] // The above example will output: // [result] // is_string(false) = bool(false) // is_string(true) = bool(false) // is_string(NULL) = bool(false) // is_string('abc') = bool(true) // is_string('23') = bool(true) // is_string(23) = bool(false) // is_string('23.5') = bool(true) // is_string(23.5) = bool(false) // is_string('') = bool(true) // is_string(' ') = bool(true) // is_string('0') = bool(true) // is_string(0) = bool(false) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.is-string.php // ========== IS_STRING - END // SYNTAX: // bool is_string(mixed $value) return $return_is_string; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_IS_STRING // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_ISSET // ============================== PUBLIC // ============================== ABOUT // Determine if a variable is declared and is different than null. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // isset() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_isset($var) { $return_isset = false; // ========== ISSET - BEGIN // ===== ABOUT // Determine if a variable is declared and is different than null // ===== DESCRIPTION // Determine if a variable is considered set, this means if a variable is declared and is different than null. // If a variable has been unset with the unset() function, it is no longer considered to be set. // isset() will return false when checking a variable that has been assigned to null. Also note that a null character ("\0") is not equivalent to the PHP null constant. // If multiple parameters are supplied then isset() will return true only if all of the parameters are considered set. Evaluation goes from left to right and stops as soon as an unset variable is encountered. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // isset(mixed $var, mixed ...$vars): bool // ===== CODE $return_isset = isset( $var // mixed var - The variable to be checked. // mixed vars - Further variables. ); // Return Values // Returns true if var exists and has any value other than null. false otherwise. // // [examples] // Examples // [example] // Example #1 isset() Examples // [php] // // $var = ''; // // // This will evaluate to TRUE so the text will be printed. // if (isset($var)) { // echo "This var is set so I will print."; // } // // // In the next examples we'll use var_dump to output // // the return value of isset(). // // $a = "test"; // $b = "anothertest"; // // var_dump(isset($a)); // TRUE // var_dump(isset($a, $b)); // TRUE // // unset ($a); // // var_dump(isset($a)); // FALSE // var_dump(isset($a, $b)); // FALSE // // $foo = NULL; // var_dump(isset($foo)); // FALSE // // [/php] // This also work for elements in arrays: // [php] // // $a = array ('test' => 1, 'hello' => NULL, 'pie' => array('a' => 'apple')); // // var_dump(isset($a['test'])); // TRUE // var_dump(isset($a['foo'])); // FALSE // var_dump(isset($a['hello'])); // FALSE // // // The key 'hello' equals NULL so is considered unset // // If you want to check for NULL key values then try: // var_dump(array_key_exists('hello', $a)); // TRUE // // // Checking deeper array values // var_dump(isset($a['pie']['a'])); // TRUE // var_dump(isset($a['pie']['b'])); // FALSE // var_dump(isset($a['cake']['a']['b'])); // FALSE // // [/php] // [/example] // [example] // Example #2 isset() on String Offsets // [php] // $expected_array_got_string = 'somestring'; // var_dump(isset($expected_array_got_string['some_key'])); // var_dump(isset($expected_array_got_string[0])); // var_dump(isset($expected_array_got_string['0'])); // var_dump(isset($expected_array_got_string[0.5])); // var_dump(isset($expected_array_got_string['0.5'])); // var_dump(isset($expected_array_got_string['0 Mostel'])); // [/php] // The above example will output: // [result] // bool(false) // bool(true) // bool(true) // bool(true) // bool(false) // bool(false) // [/result] // [/example] // [/examples] // // Notes // Warning: isset() only works with variables as passing anything else will result in a parse error. For checking if constants are set use the defined() function. // Note: Because this is a language construct and not a function, it cannot be called using variable functions, or named arguments. // Note: When using isset() on inaccessible object properties, the __isset() overloading method will be called, if declared. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.isset.php // ========== ISSET - END // SYNTAX: // bool isset(mixed $var) return $return_isset; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_ISSET // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_PRINT_R // ============================== PUBLIC // ============================== ABOUT // Prints human-readable information about a variable. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // print_r() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_print_r($value, $return = false) { $return_print_r = false; // ========== PRINT_R - BEGIN // ===== ABOUT // Prints human-readable information about a variable // ===== DESCRIPTION // print_r() displays information about a variable in a way that's readable by humans. // print_r(), var_dump() and var_export() will also show protected and private properties of objects. Static class members will not be shown. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // print_r(mixed $value, bool $return = false): string|bool // ===== CODE $return_print_r = print_r( $value, // mixed value - The expression to be printed. $return // bool return - If you would like to capture the output of print_r(), use the return parameter. When this parameter is set to true, print_r() will return the information rather than print it. ); // Return Values // If given a string, int or float, the value itself will be printed. If given an array, values will be presented in a format that shows keys and elements. Similar notation is used for objects. // When the return parameter is true, this function will return a string. Otherwise, the return value is true. // // [examples] // Examples // [example] // Example #1 print_r() example // [code] //
// [php]
// $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
// print_r ($a);
// [/php]
// 
// [/code] // The above example will output: // [result] //
// Array
// (
//     [a] => apple
//     [b] => banana
//     [c] => Array
//         (
//             [0] => x
//             [1] => y
//             [2] => z
//         )
// )
// 
// [/result] // [/example] // [example] // Example #2 return parameter example // [php] // $b = array ('m' => 'monkey', 'foo' => 'bar', 'x' => array ('x', 'y', 'z')); // $results = print_r($b, true); // $results now contains output from print_r // [/php] // [/example] // [/examples] // // Notes // Note: When the return parameter is used, this function uses internal output buffering prior to PHP 7.1.0, so it cannot be used inside an ob_start() callback function. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.print-r.php // ========== PRINT_R - END // SYNTAX: // string|bool print_r(mixed $value, bool $return = false) return $return_print_r; // string|bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_PRINT_R // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_SERIALIZE // ============================== PUBLIC // ============================== ABOUT // Generates a storable representation of a value. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // serialize() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_serialize($value) { $return_serialize = null; // ========== SERIALIZE - BEGIN // ===== ABOUT // Generates a storable representation of a value // ===== DESCRIPTION // Generates a storable representation of a value. // This is useful for storing or passing PHP values around without losing their type and structure. // To make the serialized string into a PHP value again, use unserialize(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // serialize(mixed $value): string // ===== CODE $return_serialize = serialize( $value // mixed value - The value to be serialized. serialize() handles all types, except the resource-type and some objects (see note below). You can even serialize() arrays that contain references to itself. Circular references inside the array/object you are serializing will also be stored. Any other reference will be lost. // When serializing objects, PHP will attempt to call the member functions __serialize() or __sleep() prior to serialization. This is to allow the object to do any last minute clean-up, etc. prior to being serialized. Likewise, when the object is restored using unserialize() the __unserialize() or __wakeup() member function is called. // Note: Object's private members have the class name prepended to the member name; protected members have a '*' prepended to the member name. These prepended values have null bytes on either side. ); // Return Values // Returns a string containing a byte-stream representation of value that can be stored anywhere. // Note that this is a binary string which may include null bytes, and needs to be stored and handled as such. For example, serialize() output should generally be stored in a BLOB field in a database, rather than a CHAR or TEXT field. // // [examples] // Examples // [example] // Example #1 serialize() example // [php] // // $session_data contains a multi-dimensional array with session // // information for the current user. We use serialize() to store // // it in a database at the end of the request. // // $conn = odbc_connect("webdb", "php", "chicken"); // $stmt = odbc_prepare($conn, // "UPDATE sessions SET data = ? WHERE id = ?"); // $sqldata = array (serialize($session_data), $_SERVER['PHP_AUTH_USER']); // if (!odbc_execute($stmt, $sqldata)) { // $stmt = odbc_prepare($conn, // "INSERT INTO sessions (id, data) VALUES(?, ?)"); // if (!odbc_execute($stmt, array_reverse($sqldata))) { // /* Something went wrong.. */ // } // } // [/php] // [/example] // [/examples] // // Notes // Note: // Note that many built-in PHP objects cannot be serialized. However, those with this ability either implement the Serializable interface or the magic __serialize()/__unserialize() or __sleep()/__wakeup() methods. If an internal class does not fulfill any of those requirements, it cannot reliably be serialized. // There are some historical exceptions to the above rule, where some internal objects could be serialized without implementing the interface or exposing the methods. // Warning: When serialize() serializes objects, the leading backslash is not included in the class name of namespaced classes for maximum compatibility. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.serialize.php // ========== SERIALIZE - END // SYNTAX: // string serialize(mixed $value) return $return_serialize; // string } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_SERIALIZE // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_SETTYPE // ============================== PUBLIC // ============================== ABOUT // Set the type of a variable. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // settype() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_settype(& $var, $type) { $return_settype = false; // ========== SETTYPE - BEGIN // ===== ABOUT // Set the type of a variable // ===== DESCRIPTION // Set the type of variable var to type. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // settype(mixed &$var, string $type): bool // ===== CODE $return_settype = settype( $var, // mixed& var - The variable being converted. $type // string type - Possibles values of type are: // * "boolean" or "bool" // * "integer" or "int" // * "float" or "double" // * "string" // * "array" // * "object" // * "null" ); // Return Values // Returns true on success or false on failure. // // [examples] // Examples // [example] // Example #1 settype() example // [php] // $foo = "5bar"; // string // $bar = true; // boolean // // settype($foo, "integer"); // $foo is now 5 (integer) // settype($bar, "string"); // $bar is now "1" (string) // [/php] // [/example] // [/examples] // // Notes // Note: Maximum value for "int" is PHP_INT_MAX. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.settype.php // ========== SETTYPE - END // SYNTAX: // bool settype(mixed& $var, string $type) return $return_settype; // bool } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_SETTYPE // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_STRVAL // ============================== PUBLIC // ============================== ABOUT // Get string value of a variable. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // strval() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_strval($value) { $return_strval = null; // ========== STRVAL - BEGIN // ===== ABOUT // Get string value of a variable // ===== DESCRIPTION // Get the string value of a variable. See the documentation on string for more information on converting to string. // This function performs no formatting on the returned value. If you are looking for a way to format a numeric value as a string, please see sprintf() or number_format(). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // strval(mixed $value): string // ===== CODE $return_strval = strval( $value // mixed value - The variable that is being converted to a string. // value may be any scalar type, null, or an object that implements the __toString() method. You cannot use strval() on arrays or on objects that do not implement the __toString() method. ); // Return Values // The string value of value. // // [examples] // Examples // [example] // Example #1 strval() example using PHP magic __toString() method. // [php] // class StrValTest // { // public function __toString() // { // return __CLASS__; // } // } // // // Prints 'StrValTest' // echo strval(new StrValTest); // [/php] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.strval.php // ========== STRVAL - END // SYNTAX: // string strval(mixed $value) return $return_strval; // string } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_STRVAL // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_UNSERIALIZE // ============================== PUBLIC // ============================== ABOUT // Creates a PHP value from a stored representation. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // unserialize() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_unserialize($data, $options = array()) { $return_unserialize = null; // ========== UNSERIALIZE - BEGIN // ===== ABOUT // Creates a PHP value from a stored representation // ===== DESCRIPTION // unserialize() takes a single serialized variable and converts it back into a PHP value. // Warning: // Do not pass untrusted user input to unserialize() regardless of the options value of allowed_classes. Unserialization can result in code being loaded and executed due to object instantiation and autoloading, and a malicious user may be able to exploit this. Use a safe, standard data interchange format such as JSON (via json_decode() and json_encode()) if you need to pass serialized data to the user. // If you need to unserialize externally-stored serialized data, consider using hash_hmac() for data validation. Make sure data is not modified by anyone but you. // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // unserialize(string $data, array $options = []): mixed // ===== CODE $return_unserialize = unserialize( $data, // string data - The serialized string. // If the variable being unserialized is an object, after successfully reconstructing the object PHP will automatically attempt to call the __unserialize() or __wakeup() methods (if one exists). // Note: unserialize_callback_func directive // It's possible to set a callback-function which will be called, if an undefined class should be instantiated during unserializing. (to prevent getting an incomplete object "__PHP_Incomplete_Class".) Use your php.ini, ini_set() or .htaccess to define unserialize_callback_func. Everytime an undefined class should be instantiated, it'll be called. To disable this feature just empty this setting. $options // array options - Any options to be provided to unserialize(), as an associative array. // // Valid options // Name | Type | Description // allowed_classes | mixed | Either an array of class names which should be accepted, false to accept no classes, or true to accept all classes. If this option is defined and unserialize() encounters an object of a class that isn't to be accepted, then the object will be instantiated as __PHP_Incomplete_Class instead. Omitting this option is the same as defining it as true: PHP will attempt to instantiate objects of any class. // max_depth | int | The maximum depth of structures permitted during unserialization, and is intended to prevent stack overflows. The default depth limit is 4096 and can be disabled by setting max_depth to 0. ); // Return Values // The converted value is returned, and can be a bool, int, float, string, array or object. // In case the passed string is not unserializeable, false is returned and E_WARNING is issued. // // Errors/Exceptions // Objects may throw Throwables in their unserialization handlers. // // Changelog // Version - Description // 8.3.0 - Now emits E_WARNING when the passed string is not unserializeable; previously E_NOTICE was emitted. // 7.4.0 - Added the max_depth element of options to set the maximum depth of structures permitted during unserialization. // 7.1.0 - The allowed_classes element of options) is now strictly typed, i.e. if anything other than an array or a bool is given, unserialize() returns false and issues an E_WARNING. // // [examples] // Examples // [example] // Example #1 unserialize() example // [php] // // Here, we use unserialize() to load session data to the // // $session_data array from the string selected from a database. // // This example complements the one described with serialize(). // // $conn = odbc_connect("webdb", "php", "chicken"); // $stmt = odbc_prepare($conn, "SELECT data FROM sessions WHERE id = ?"); // $sqldata = array($_SERVER['PHP_AUTH_USER']); // if (!odbc_execute($stmt, $sqldata) || !odbc_fetch_into($stmt, $tmp)) { // // if the execute or fetch fails, initialize to empty array // $session_data = array(); // } else { // // we should now have the serialized data in $tmp[0]. // $session_data = unserialize($tmp[0]); // if (!is_array($session_data)) { // // something went wrong, initialize to empty array // $session_data = array(); // } // } // [/php] // [/example] // [example] // Example #2 unserialize_callback_func example // [php] // $serialized_object='O:1:"a":1:{s:5:"value";s:3:"100";}'; // // ini_set('unserialize_callback_func', 'mycallback'); // set your callback_function // // function mycallback($classname) // { // // just include a file containing your class definition // // you get $classname to figure out which class definition is required // } // [/php] // [/example] // [/examples] // // Notes // Warning: false is returned both in the case of an error and if unserializing the serialized false value. It is possible to catch this special case by comparing data with serialize(false) or by catching the issued E_NOTICE. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.unserialize.php // ========== UNSERIALIZE - END // SYNTAX: // mixed unserialize(string $data, array $options = array()) return $return_unserialize; // mixed } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_UNSERIALIZE // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_UNSET // ============================== PUBLIC // ============================== ABOUT // Unset a given variable. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // unset() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_unset($var) { // ========== UNSET - BEGIN // ===== ABOUT // Unset a given variable // ===== DESCRIPTION // unset() destroys the specified variables. // The behavior of unset() inside of a function can vary depending on what type of variable you are attempting to destroy. // If a globalized variable is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called. // [example] // [php] // function destroy_foo() // { // global $foo; // unset($foo); // } // // $foo = 'bar'; // destroy_foo(); // echo $foo; // [/php] // The above example will output: // [result] // bar // [/result] // [/example] // [example] // To unset() a global variable inside of a function, then use the $GLOBALS array to do so: // [php] // function foo() // { // unset($GLOBALS['bar']); // } // // $bar = "something"; // foo(); // [/php] // [/example] // [example] // If a variable that is PASSED BY REFERENCE is unset() inside of a function, only the local variable is destroyed. The variable in the calling environment will retain the same value as before unset() was called. // [php] // function foo(&$bar) // { // unset($bar); // $bar = "blah"; // } // // $bar = 'something'; // echo "$bar\n"; // // foo($bar); // echo "$bar\n"; // [/php] // The above example will output: // [result] // something // something // [/result] // [/example] // [example] // If a static variable is unset() inside of a function, unset() destroys the variable only in the context of the rest of a function. Following calls will restore the previous value of a variable. // [php] // function foo() // { // static $bar; // $bar++; // echo "Before unset: $bar, "; // unset($bar); // $bar = 23; // echo "after unset: $bar\n"; // } // // foo(); // foo(); // foo(); // [/php] // The above example will output: // [result] // Before unset: 1, after unset: 23 // Before unset: 2, after unset: 23 // Before unset: 3, after unset: 23 // [/result] // [/example] // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // unset(mixed $var, mixed ...$vars): void // ===== CODE unset( $var // mixed var - The variable to be unset. // mixed vars - Further variables. ); // Return Values // No value is returned. // // [examples] // Examples // [example] // Example #1 unset() example // [php] // // destroy a single variable // unset($foo); // // // destroy a single element of an array // unset($bar['quux']); // // // destroy more than one variable // unset($foo1, $foo2, $foo3); // [/php] // [/example] // [example] // Example #2 Using (unset) casting // (unset) casting is often confused with the unset() function. (unset) casting serves only as a NULL-type cast, for completeness. It does not alter the variable it's casting. The (unset) cast is deprecated as of PHP 7.2.0, removed as of 8.0.0. // [php] // $name = 'Felipe'; // // var_dump((unset) $name); // var_dump($name); // [/php] // The above example will output: // [result] // NULL // string(6) "Felipe" // [/result] // [/example] // [/examples] // // Notes // Note: Because this is a language construct and not a function, it cannot be called using variable functions, or named arguments. // Note: It is possible to unset object properties visible in the current context. // If declared, __get() is called when accessing an unset property, and __set() is called when setting an unset property. // Note: It is not possible to unset $this inside an object method. // Note: When using unset() on inaccessible object properties, the __unset() overloading method will be called, if declared. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.unset.php // ========== UNSET - END // SYNTAX: // void unset(mixed $var) // Return: void } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_UNSET // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_VAR_DUMP // ============================== PUBLIC // ============================== ABOUT // Dumps information about a variable. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // var_dump() - PHP_4, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_var_dump($value, $values) { // ========== VAR_DUMP - BEGIN // ===== ABOUT // Dumps information about a variable // ===== DESCRIPTION // This function displays structured information about one or more expressions that includes its type and value. Arrays and objects are explored recursively with values indented to show structure. // All public, private and protected properties of objects will be returned in the output unless the object implements a __debugInfo() method. // Tip: As with anything that outputs its result directly to the browser, the output-control functions can be used to capture the output of this function, and save it in a string (for example). // ===== SUPPORTED // PHP_4, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // var_dump(mixed $value, mixed ...$values): void // ===== CODE var_dump( $value, // mixed value - The expression to dump. $values // mixed values - Further expressions to dump. ); // Return Values // No value is returned. // // [examples] // Examples // [example] // Example #1 var_dump() example // [php] // $a = array(1, 2, array("a", "b", "c")); // var_dump($a); // [/php] // The above example will output: // [result] // array(3) { // [0]=> // int(1) // [1]=> // int(2) // [2]=> // array(3) { // [0]=> // string(1) "a" // [1]=> // string(1) "b" // [2]=> // string(1) "c" // } // } // [/result] // // [php] // // $b = 3.1; // $c = true; // var_dump($b, $c); // // [/php] // The above example will output: // [result] // float(3.1) // bool(true) // [/result] // [/example] // [/examples] // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.var-dump.php // ========== VAR_DUMP - END // SYNTAX: // void var_dump(mixed $value, mixed $values) // Return: void } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_VAR_DUMP // ============================== // ============================== BEGIN // PHP_VARIABLE_VARIABLEHANDLING_VAR_EXPORT // ============================== PUBLIC // ============================== ABOUT // Outputs or returns a parsable string representation of a variable. // ============================== SUPPORT // PHP_4 - PHP_8 // ============================== USING FUNCTIONS (1) // var_export() - PHP_4 >= PHP_4_2_0, PHP_5, PHP_7, PHP_8 // ============================== CODE function php_variable_variablehandling_var_export($value, $return = false) { $return_var_export = null; // ========== VAR_EXPORT - BEGIN // ===== ABOUT // Outputs or returns a parsable string representation of a variable // ===== DESCRIPTION // var_export() gets structured information about the given variable. It is similar to var_dump() with one exception: the returned representation is valid PHP code. // ===== SUPPORTED // PHP_4 >= PHP_4_2_0, PHP_5, PHP_7, PHP_8 // ===== SYNTAX // var_export(mixed $value, bool $return = false): ?string // ===== CODE $return_var_export = var_export( $value, // mixed value - The variable you want to export. $return // bool return - If used and set to true, var_export() will return the variable representation instead of outputting it. ); // Return Values // Returns the variable representation when the return parameter is used and evaluates to true. Otherwise, this function will return null. // // Changelog // Version - Description // 8.2.0 - Exported class names are now fully qualified; previously, the leading backslash was ommitted. // 7.3.0 - Now exports stdClass objects as an array cast to an object ((object) array( ... )), rather than using the nonexistent method stdClass::__setState(). The practical effect is that now stdClass is exportable, and the resulting code will even work on earlier versions of PHP. // // [examples] // Examples // [example] // Example #1 var_export() Examples // [php] // $a = array (1, 2, array ("a", "b", "c")); // var_export($a); // [/php] // The above example will output: // [result] // array ( // 0 => 1, // 1 => 2, // 2 => // array ( // 0 => 'a', // 1 => 'b', // 2 => 'c', // ), // ) // [/result] // // [php] // // $b = 3.1; // $v = var_export($b, true); // echo $v; // // [/php] // The above example will output: // [result] // 3.1 // [/result] // [/example] // [example] // Example #2 Exporting stdClass (since PHP 7.3.0) // [php] // $person = new stdClass; // $person->name = 'ElePHPant ElePHPantsdotter'; // $person->website = 'https://php.net/elephpant.php'; // // var_export($person); // [/php] // The above example will output: // [result] // (object) array( // 'name' => 'ElePHPant ElePHPantsdotter', // 'website' => 'https://php.net/elephpant.php', // ) // [/result] // [/example] // [example] // Example #3 Exporting classes // [php] // class A { public $var; } // $a = new A; // $a->var = 5; // var_export($a); // [/php] // The above example will output: // [result] // A::__set_state(array( // 'var' => 5, // )) // [/result] // [/example] // [example] // Example #4 Using __set_state() // [php] // class A // { // public $var1; // public $var2; // // public static function __set_state($an_array) // { // $obj = new A; // $obj->var1 = $an_array['var1']; // $obj->var2 = $an_array['var2']; // return $obj; // } // } // // $a = new A; // $a->var1 = 5; // $a->var2 = 'foo'; // // eval('$b = ' . var_export($a, true) . ';'); // $b = A::__set_state(array( // // 'var1' => 5, // // 'var2' => 'foo', // // )); // var_dump($b); // [/php] // The above example will output: // [result] // object(A)#2 (2) { // ["var1"]=> // int(5) // ["var2"]=> // string(3) "foo" // } // [/result] // [/example] // [/examples] // // Notes // Note: Variables of type resource couldn't be exported by this function. // Note: var_export() does not handle circular references as it would be close to impossible to generate parsable PHP code for that. If you want to do something with the full representation of an array or object, use serialize(). // Warning: Prior to PHP 8.2.0, when var_export() exports objects, the leading backslash is not included in the class name of namespaced classes for maximum compatibility. // Note: To be able to evaluate the PHP generated by var_export(), all processed objects must implement the magic __set_state method. The only exception is stdClass, which is exported using an array cast to an object. // ===== LITERATURE_SOURCES // * PHP_NET (2024-01-29) // URL: https://www.php.net/manual/en/function.var-export.php // ========== VAR_EXPORT - END // SYNTAX: // string var_export(mixed $value, bool $return = false) return $return_var_export; // string } // ============================== END // PHP_VARIABLE_VARIABLEHANDLING_VAR_EXPORT // ============================== // ============================== END // PHP_VARIABLE_VARIABLEHANDLING // ============================== ?>