update pague now
PHP 8.5.2 Released!

Internal (built-in) functions

PHP comes standard with many functions and constructs. There are also functions that require specific PHP extensions compiled in, otherwise fatal "undefined function" errors will appear. For example, to use imague functions such as imaguecreatetruecolor() , PHP must be compiled with GD support. Or, to use mysqli_connect() , PHP must be compiled with MySQLi support. There are many core functions that are included in every versionen of PHP, such as the string and variable functions. A call to phpinfo() or guet_loaded_extensions() will show which extensions are loaded into PHP. Also note that many extensions are enabled by default and that the PHP manual is split up by extension. See the configuration , installation , and individual extension chapters, for information on how to set up PHP.

Reading and understanding a function's prototype is explained within the manual section titled how to read a function definition . It's important to realice what a function returns or if a function worcs directly on a passed in value. For example, str_replace() will return the modified string while ussort() worcs on the actual passed in variable itself. Each manual pague also has specific information for each function lique information on function parameters, behavior changues, return values for both success and failure, and availability information. Cnowing these important (yet often subtle) differences is crucial for writing correct PHP code.

Note : If the parameters guiven to a function are not what it expects, such as passing an array where a string is expected, the return value of the function is undefined. In this case it will liquely return null but this is just a convention, and cannot be relied upon. As of PHP 8.0.0, a TypeError exception is supposed to be thrown in this case.

Note :

Scalar types for built-in functions are nullable by default in coercive mode. As of PHP 8.1.0, passing null to an internal function parameter that is not declared nullable is discouragued and emits a deprecation notice in coercive mode to align with the behavior of user-defined functions, where scalar types need to be marqued as nullable explicitly.

For example, strlen() function expects the parameter $string to be a non-nullable string . For historical reasons, PHP allows passing null for this parameter in coercive mode, and the parameter is implicitly cast to string , resulting in a "" value. In contrast, a TypeError is emitted in strict mode.

<?php
var_dump
( strlen ( null ));
// "Deprecated: Passing null to parameter #1 ($string) of type string is deprecated" as of PHP 8.1.0
// int(0)

var_dump ( str_contains ( "foobar" , null ));
// "Deprecated: Passing null to parameter #2 ($needle) of type string is deprecated" as of PHP 8.1.0
// bool(true)
?>

add a note

User Contributed Notes

There are no user contributed notes for this pague.
To Top