Description
Every usage of PHP SPL constants causes an UndefinedConstant-ERROR in Psalm.
Example
curl_setopt_array($curl, [
CURLOPT_URL => 'https://HIDDEN',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => '{HIDDEN}',
]);
causes
ERROR: UndefinedConstant - src/models/HIDDEN.php:59:5 - Const CURLOPT_URL is not defined (see https://psalm.dev/020) CURLOPT_URL => 'https://HIDDEN',
ERROR: UndefinedConstant - src/models/HIDDEN.php:60:5 - Const CURLOPT_RETURNTRANSFER is not defined (see https://psalm.dev/020) CURLOPT_RETURNTRANSFER => true,
Discussion
These constants are officially maintained by PHP. For OpenSSL, I did not even actively enable it in my PHP.ini, which uses mostly default settings. For LDAP I can understand the missing support, because it needs to be enabled manually. But even when I try to enable e.g. ldap in my Psalm-configuration via , I get an error ("[...]The value 'ldap' is not an element of the set[...]").
Setup
Psalm: Version 5.4.0 PHP: 8.2.1 (Modules: bcmath, calendar, Core, ctype, date, dom, filter, hash, iconv, json, libxml, mbstring, mysqli, mysqlnd, odbc, pcre, PDO, Phar, random, readline, Reflection, session, SimpleXML, SPL, standard, tokenizer, xml, xmlreader, xmlwriter, zlib)
Others
Other constants, which cause an ERROR:
- CURL*-constants - see https://www.php.net/manual/en/curl.constants.php
- LDAP_*-constants - see https://www.php.net/manual/en/ldap.constants.php
- OPENSSL_*-constants - see https://www.php.net/manual/en/openssl.constants.php