PHP "Call to undefined function" - Missing Extension in CI
PHP tried to call a function that is not defined in this runtime. Most often the function belongs to an extension that is not enabled on the CI runner (e.g. mb_* from mbstring, curl_* from curl, intl functions).
What this error means
A script fails with "Call to undefined function <name>()". The same code runs locally because your local PHP has the extension enabled, but the runner’s PHP does not.
PHP Fatal error: Uncaught Error: Call to undefined function mb_strlen() in
/app/src/Text.php:15Common causes
The providing extension is not enabled
mb_strlen needs mbstring, curl_init needs curl, json_encode needs json, Normalizer/intl_* need intl. If the extension is missing, the function is undefined.
A package function not autoloaded
Global helper functions from a package require its files autoload entry. If Composer’s autoloader was not generated, those functions are undefined.
How to fix it
Enable the extension on the runner
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, intl, curl, jsonConfirm which functions/extensions are loaded
- Run
php -mto list loaded extensions. - Run
php -r "var_dump(function_exists('mb_strlen'));"to test a specific function. - If it is a package helper, run
composer dump-autoloadsofilesautoloads register.
How to prevent it
- Enable every required extension in CI via setup-php to mirror production.
- Assert critical functions exist early in the job (
php -m). - Declare extension requirements (
ext-*) incomposer.jsonso Composer fails loudly.