You are here

PHP wrapper functions in Drupal 10

Same name and namespace in other branches
  1. 8 core/includes/common.inc \php_wrappers
  2. 7 includes/common.inc \php_wrappers
  3. 9 core/includes/common.inc \php_wrappers

Functions that are wrappers or custom implementations of PHP functions.

Certain PHP functions should not be used in Drupal. Instead, Drupal's replacement functions should be used.

For example, for improved or more secure UTF8-handling, or RFC-compliant handling of URLs in Drupal.

For ease of use and memorizing, all these wrapper functions use the same name as the original PHP function, but prefixed with "drupal_". Beware, however, that not all wrapper functions support the same arguments as the original functions.

You should always use these wrapper functions in your code.

Wrong:

$my_substring = substr($original_string, 0, 5);

Correct:

$my_substring = mb_substr($original_string, 0, 5);

File

core/includes/common.inc, line 17
Common functions that many Drupal modules will need to reference.

Functions

Namesort descending Location Description
drupal_register_shutdown_function core/includes/bootstrap.inc Registers a function for execution on shutdown.
FileSystemInterface::basename core/lib/Drupal/Core/File/FileSystemInterface.php Gets the filename from a given path.
FileSystemInterface::chmod core/lib/Drupal/Core/File/FileSystemInterface.php Sets the permissions on a file or directory.
FileSystemInterface::dirname core/lib/Drupal/Core/File/FileSystemInterface.php Gets the name of the directory from a given path.
FileSystemInterface::mkdir core/lib/Drupal/Core/File/FileSystemInterface.php Creates a directory, optionally creating missing components in the path to the directory.
FileSystemInterface::moveUploadedFile core/lib/Drupal/Core/File/FileSystemInterface.php Moves an uploaded file to a new location.
FileSystemInterface::realpath core/lib/Drupal/Core/File/FileSystemInterface.php Resolves the absolute filepath of a local URI or filepath.
FileSystemInterface::rmdir core/lib/Drupal/Core/File/FileSystemInterface.php Removes a directory.
FileSystemInterface::tempnam core/lib/Drupal/Core/File/FileSystemInterface.php Creates a file with a unique filename in the specified directory.
FileSystemInterface::unlink core/lib/Drupal/Core/File/FileSystemInterface.php Deletes a file.
Unicode::lcfirst core/lib/Drupal/Component/Utility/Unicode.php Converts the first character of a UTF-8 string to lowercase.
Unicode::ucwords core/lib/Drupal/Component/Utility/Unicode.php Capitalizes the first character of each word in a UTF-8 string.
UrlHelper::buildQuery core/lib/Drupal/Component/Utility/UrlHelper.php Parses an array into a valid, rawurlencoded query string.
UrlHelper::parse core/lib/Drupal/Component/Utility/UrlHelper.php Parses a URL string into its path, query, and fragment components.