-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resource to opaque object migration #6
Comments
About ZIP, I don't know if it worth the work, as we already have a full OO API. |
@remicollet I was wondering about this a while ago. See my question at php/php-src#5601 (comment) I even had a try at the conversion, but for me, it didn't go as easy as it seemed first, so I stopped. As far as I remember, my main problem was that the data structures used by the OO and procedural interface don't align really well. Is it really the case? If so, then I'd also prefer deprecating the old API. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Because this is an anticipated failure mode of hosting this internal coordination tracker on GitHub, I'm going to err on the side of over-moderation and say: This is not the place to have this discussion. These issues have been discussed extensively on the PHP internals list in the past, and that would also be the place to revisit any decisions. |
BZ2 should be filed under ext/standard/streams |
Edit to add: I just remembered why I never moved on this. |
Okay, expanded idea:
Then callsites look like:
Edit to add: While php_stream_from_zval() doesn't currently throw exceptions, I'm sure we could use a version which does throw a proper TypeError. |
On the other hand.... I've just actually sat down to do grep -r php_stream_to_zval ext/ | wc -l and the answer is only 60. So I may be making a tempest in a teapot. |
PHP 8.0+ is migrating away from the `resource` type in favor of normal classes, see <php/php-tasks#6>. Code should generally check for return values being false rather than using is_resource(). Bug: T260735 Change-Id: Iad84a60b302b22497f7ec1282e4e6223a32ebaeb
For completeness of the list, the following extensions also saw resource to object changes in PHP 8.0:
The status of the Enchant extension is not 100% clear to me. The change from resource to object is mentioned in the changelog, but the associated PR discussion gives the impression that the commit got reverted: php/php-src#5533 |
Another one for which I can't seem to determine the status is SNMP. |
Have a look at commit: php/php-src@cd3e04d for Enchant |
Thanks @Girgias ! |
Me neither, but it seems there is an OOP API as of PHP 5.4.0 (http://github.com/php/php-src/commit/5e82e334ddffcf577542a74a37f3388d14790686) which is not documented at all. PS: oh, it is documented. |
@cmb69 Thanks for taking a look! Still not entirely clear what the change in PHP 8.0 is related to that. Let's hope someone figures it out and adds it to the changelog (if relevant enough) ;-) |
…t conversion There are on-going efforts to remove the use of resources and change these to opaque (final, non-serializable, non-constructable) objects. This commit addresses detection of the use of the new classes introduced as part of these efforts in PHP 8.0. :point_right: Note: There is currently no sniff which examines how the return value of the affected function calls is handled. This could possible be added at some point in the future, though would be complicated, what with the many ways in which the return value could be checked. Related to 809 Refs: * php/php-tasks#6 * https://wiki.php.net/rfc/resource_to_object_conversion What's addressed in this commit CURL > . curl_init() will now return a CurlHandle object rather than a resource. > Return value checks using is_resource() should be replaced with > checks for `false`. The curl_close() function no longer has an effect, > instead the CurlHandle instance is automatically destroyed if it is no > longer referenced. > . curl_multi_init() will now return a CurlMultiHandle object rather than a > resource. Return value checks using is_resource() should be replaced with > checks for `false`. The curl_multi_close() function no longer has an effect, > instead the CurlMultiHandle instance is automatically destroyed if it is no > longer referenced. > . curl_share_init() will now return a CurlShareHandle object rather than a > resource. Return value checks using is_resource() should be replaced with > checks for `false`. The curl_share_close() function no longer has an effect, > instead the CurlShareHandle instance is automatically destroyed if it is no > longer referenced. Refs: * https://github.com/php/php-src/blob/670052c427eb08a67577789e3b00e56a4fd640a7/UPGRADING#L1025-L1039 * php/php-src 5402 * php/php-src@b516566 Enchant > . enchant_broker_init() will now return an EnchantBroker object rather than > a resource. Return value checks using is_resource() should be replaced with > checks for `false`. > . enchant_broker_request_dict() and enchant_broker_request_pwl_dict() will now > return an EnchantDictionary object rather than a resource. Return value > checks using is_resource() should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/670052c427eb08a67577789e3b00e56a4fd640a7/UPGRADING#L296-L301 * php/php-src 5577 * php/php-src@cd3e04d GD > . The GD extension now uses a GdImage objects as the underlying data structure > for images, rather than resources. These objects are completely opaque, i.e. > they don't have any methods. Return value checks using is_resource() should > be replaced with checks for `false`. The imagedestroy() function no longer > has an effect, instead the GdImage instance is automatically destroyed if > it is no longer referenced. Refs: * https://github.com/php/php-src/blob/670052c427eb08a67577789e3b00e56a4fd640a7/UPGRADING#L315-L320 * php/php-src 4714 * php/php-src@8aad466 OpenSSL > . openssl_x509_read() and openssl_csr_sign() will now return an > OpenSSLCertificate object rather than a resource. Return value checks using > is_resource() should be replaced with checks for `false`. > . openssl_csr_new() will now return an OpenSSLCertificateSigningRequest object > rather than a resource. Return value checks using is_resource() should be > replaced with checks for `false`. > . openssl_pkey_new() will now return an OpenSSLAsymmetricKey object rather than a > resource. Return value checks using is_resource() should be replaced with > checks for `false`. Refs: * https://github.com/php/php-src/blob/670052c427eb08a67577789e3b00e56a4fd640a7/UPGRADING#L412-L414 + https://github.com/php/php-src/blob/670052c427eb08a67577789e3b00e56a4fd640a7/UPGRADING#L418-L423 * php/php-src 5860 * php/php-src@9f44eca Shmop > . shmop_open() will now return a Shmop object rather than a resource. Return > value checks using is_resource() should be replaced with checks for `false`. > The shmop_close() function no longer has an effect, and is deprecated; > instead the Shmop instance is automatically destroyed if it is no longer > referenced. Refs: * https://github.com/php/php-src/blob/670052c427eb08a67577789e3b00e56a4fd640a7/UPGRADING#L1100-1105 * php/php-src 5537 * php/php-src@18f5808 Sockets > . socket_create(), socket_create_listen(), socket_accept(), > socket_import_stream(), socket_addrinfo_connect(), socket_addrinfo_bind(), > and socket_wsaprotocol_info_import() will now return a Socket object rather > than a resource. Return value checks using is_resource() should be replaced > with checks for `false`. > . socket_addrinfo_lookup() will now return an array of AddressInfo objects > rather than resources. Refs: * https://github.com/php/php-src/blob/670052c427eb08a67577789e3b00e56a4fd640a7/UPGRADING#L509-L515 * php/php-src 5900 * php/php-src@77172c2 Sysvmsg > . msg_get_queue() will now return an SysvMessageQueue object rather than a > resource. Return value checks using is_resource() should be replaced with > checks for `false`. Refs: * https://github.com/php/php-src/blob/670052c427eb08a67577789e3b00e56a4fd640a7/UPGRADING#L635-L637 * php/php-src 5546 * php/php-src@9198faa Sysvsem > . sem_get() will now return an SysvSemaphore object rather than a resource. > Return value checks using is_resource() should be replaced with checks > for `false`. Refs: * https://github.com/php/php-src/blob/670052c427eb08a67577789e3b00e56a4fd640a7/UPGRADING#L640-L642 * php/php-src 5508 * php/php-src@eab54d2 * php/php-src@b67f699 Sysvshm > . shm_attach() will now return an SysvSharedMemory object rather than a resource. > Return value checks using is_resource() should be replaced with checks > for `false`. Refs: * https://github.com/php/php-src/blob/670052c427eb08a67577789e3b00e56a4fd640a7/UPGRADING#L647-649 * php/php-src 5499 * php/php-src@2e18b30 XML > . xml_parser_create(_ns) will now return an XMLParser object rather than a > resource. Return value checks using is_resource() should be replaced with > checks for `false`. The xml_parser_free() function no longer has an effect, > instead the XMLParser instance is automatically destroyed if it is no longer > referenced. Refs: * https://github.com/php/php-src/blob/670052c427eb08a67577789e3b00e56a4fd640a7/UPGRADING#L668-L672 * php/php-src 3526 * php/php-src@e35a3cb Zlib > . inflate_init() will now return an InflateContext object rather than a > resource. Return value checks using is_resource() should be replaced with > checks for `false`. > . deflate_init() will now return a DeflateContext object rather than a > resource. Return value checks using is_resource() should be replaced with > checks for `false`. Refs: * https://github.com/php/php-src/blob/670052c427eb08a67577789e3b00e56a4fd640a7/UPGRADING#L689-L694 * php/php-src 5680 * php/php-src@314eedb --- PHP 8.0 resource to object migrations not included in this commit XML-RPC _Superseded by the removal/unbundling of the extension in PHP 8.0, which was addressed in PR 1161._ XMLWriter > . The XMLWriter functions now accept and return, respectively, XMLWriter > objects instead of resources. The XMLWriter class was already introduced in PHP 5.1.2, so this is not a new class. ZIP Instead of migrating the resource to an object, the procedural API was deprecated in favour of the (pre-existing) OO API. This deprecation was already addressed in PR 1202.
…t conversion There are on-going efforts to remove the use of resources and change these to opaque (final, non-serializable, non-constructable) objects. This commit addresses detection of the use of these new classes introduced as part of these efforts in PHP 8.1. :point_right: Note: There is currently no sniff which examines how the return value of the affected function calls is handled. This could possible be added at some point in the future, though would be complicated, what with the many ways in which the return value could be checked. Related to 1299 Refs: * php/php-tasks#6 * https://wiki.php.net/rfc/resource_to_object_conversion What's addressed in this commit FTP > . The FTP functions now accept and return, respectively, FTP\Connection objects > instead of resources. Return value checks using is_resource() > should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/a87ccc7ca2644e327c210e68b4d98df98ad33523/UPGRADING#L74-L76 * php/php-src 5945 * php/php-src@b4503fb * php/php-src 6960 * php/php-src@68224f2 GD _Missing changelog entry._ GD font resources were converted to `GdFont` objects. Refs: * php/php-src@bc40bce#diff-bab0878b1e6efd11124071b0fde6bb1ed24552c288709cd858a29f7ebe28d5cd IMAP > . The IMAP functions now accept and return, respectively, IMAP\Connection objects > instead of resources. Return value checks using is_resource() > should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/a87ccc7ca2644e327c210e68b4d98df98ad33523/UPGRADING#L78-L81 * php/php-src 6418 * php/php-src@383779e * php/php-src 6534 * php/php-src@7f1659a * php/php-src@af68d4a LDAP > . The LDAP functions now accept and return, respectively, LDAP\Connection objects > instead of "ldap link" resources. Return value checks using is_resource() > should be replaced with checks for `false`. > . The LDAP functions now accept and return, respectively, LDAP\Result objects > instead of "ldap result" resources. Return value checks using is_resource() > should be replaced with checks for `false`. > . The LDAP functions now accept and return, respectively, LDAP\ResultEntry > objects instead of "ldap result entry" resources. Return value checks using > is_resource() should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/a87ccc7ca2644e327c210e68b4d98df98ad33523/UPGRADING#L84-L92 * php/php-src 6770 * php/php-src@cd40fc3 * php/php-src 6963 * php/php-src@e0b947a PgSQL > . The PgSQL functions now accept and return, respectively, \PgSql\Connection > objects instead of "pgsql link" resources. Return value checks using > is_resource() should be replaced with checks for `false`. > . The PgSQL functions now accept and return, respectively, \PgSql\Result > objects instead of "pgsql result" resources. Return value checks using > is_resource() should be replaced with checks for `false`. > . The PgSQL functions now accept and return, respectively, \PgSql\Lob > objects instead of "pgsql large object" resources. Return value checks > using is_resource() should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/a87ccc7ca2644e327c210e68b4d98df98ad33523/UPGRADING#L142-L150 * php/php-src 6791 * php/php-src@32aff25 PSpell > . The PSpell functions now accept and return, respectively, PSpell\Dictionary objects > instead of "pspell" resources. Return value checks using is_resource() > should be replaced with checks for `false`. > . The PSpell functions now accept and return, respectively, PSpell\Config objects > instead of "pspell config" resources. Return value checks using is_resource() > should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/a87ccc7ca2644e327c210e68b4d98df98ad33523/UPGRADING#L156-L162 * php/php-src@bd12c94 * php/php-src 6970 * php/php-src@57a635c --- PHP 8.1 resource to object migrations not included in this commit Finfo > . The fileinfo functions now accept and return, respectively, finfo objects > instead of resources. Return value checks using is_resource() > should be replaced with checks for `false`. The finfo class was already introduced in PHP 5.3.0, so this is not a new class.
…t conversion There are on-going efforts to remove the use of resources and change these to opaque (final, non-serializable, non-constructable) objects. This commit addresses detection of the use of these new classes introduced as part of these efforts in PHP 8.1. :point_right: Note: There is currently no sniff which examines how the return value of the affected function calls is handled. This could possible be added at some point in the future, though would be complicated, what with the many ways in which the return value could be checked. Related to 1299 Refs: * php/php-tasks#6 * https://wiki.php.net/rfc/resource_to_object_conversion What's addressed in this commit FTP > . The FTP functions now accept and return, respectively, FTP\Connection objects > instead of resources. Return value checks using is_resource() > should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/a87ccc7ca2644e327c210e68b4d98df98ad33523/UPGRADING#L74-L76 * php/php-src 5945 * php/php-src@b4503fb * php/php-src 6960 * php/php-src@68224f2 GD _Missing changelog entry._ GD font resources were converted to `GdFont` objects. Refs: * php/php-src@bc40bce#diff-bab0878b1e6efd11124071b0fde6bb1ed24552c288709cd858a29f7ebe28d5cd IMAP > . The IMAP functions now accept and return, respectively, IMAP\Connection objects > instead of resources. Return value checks using is_resource() > should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/a87ccc7ca2644e327c210e68b4d98df98ad33523/UPGRADING#L78-L81 * php/php-src 6418 * php/php-src@383779e * php/php-src 6534 * php/php-src@7f1659a * php/php-src@af68d4a LDAP > . The LDAP functions now accept and return, respectively, LDAP\Connection objects > instead of "ldap link" resources. Return value checks using is_resource() > should be replaced with checks for `false`. > . The LDAP functions now accept and return, respectively, LDAP\Result objects > instead of "ldap result" resources. Return value checks using is_resource() > should be replaced with checks for `false`. > . The LDAP functions now accept and return, respectively, LDAP\ResultEntry > objects instead of "ldap result entry" resources. Return value checks using > is_resource() should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/a87ccc7ca2644e327c210e68b4d98df98ad33523/UPGRADING#L84-L92 * php/php-src 6770 * php/php-src@cd40fc3 * php/php-src 6963 * php/php-src@e0b947a PgSQL > . The PgSQL functions now accept and return, respectively, \PgSql\Connection > objects instead of "pgsql link" resources. Return value checks using > is_resource() should be replaced with checks for `false`. > . The PgSQL functions now accept and return, respectively, \PgSql\Result > objects instead of "pgsql result" resources. Return value checks using > is_resource() should be replaced with checks for `false`. > . The PgSQL functions now accept and return, respectively, \PgSql\Lob > objects instead of "pgsql large object" resources. Return value checks > using is_resource() should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/a87ccc7ca2644e327c210e68b4d98df98ad33523/UPGRADING#L142-L150 * php/php-src 6791 * php/php-src@32aff25 PSpell > . The PSpell functions now accept and return, respectively, PSpell\Dictionary objects > instead of "pspell" resources. Return value checks using is_resource() > should be replaced with checks for `false`. > . The PSpell functions now accept and return, respectively, PSpell\Config objects > instead of "pspell config" resources. Return value checks using is_resource() > should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/a87ccc7ca2644e327c210e68b4d98df98ad33523/UPGRADING#L156-L162 * php/php-src@bd12c94 * php/php-src 6970 * php/php-src@57a635c --- PHP 8.1 resource to object migrations not included in this commit Finfo > . The fileinfo functions now accept and return, respectively, finfo objects > instead of resources. Return value checks using is_resource() > should be replaced with checks for `false`. The finfo class was already introduced in PHP 5.3.0, so this is not a new class.
…t conversion There are on-going efforts to remove the use of resources and change these to opaque (final, non-serializable, non-constructable) objects. This commit addresses detection of the use of these new classes introduced as part of these efforts in PHP 8.4. As these classes are all namespaced and reserve additional top-level namespaces for PHP, the `Namespaces\ReservedNames` sniff has also been updated. :point_right: Note: There is currently no sniff which examines how the return value of the affected function calls is handled. This could possible be added at some point in the future, though would be complicated, what with the many ways in which the return value could be checked. Related to 1731 Refs: * php/php-tasks#6 * https://wiki.php.net/rfc/resource_to_object_conversion What's addressed in this commit DBA > . dba_open() and dba_popen() will now return a Dba\Connection > object rather than a resource. Return value checks using is_resource() > should be replaced with checks for `false`. Refs: * Not in changelog yet, open PR php/php-src 15339 * php/php-src 14329 * php/php-src@2097237 ODBC > . odbc_connect() and odbc_pconnect() will now return an Odbc\Connection > object rather than a resource. Return value checks using is_resource() > should be replaced with checks for `false`. > . odbc_prepare(), odbc_exec(), and various other functions will now return > an Odbc\Result object rather than a resource. Return value checks using > is_resource() should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/e1c8329b8ca9222f7a5f48c1ca19e95129b807c0/UPGRADING#L86-L91 * php/php-src 12040 * php/php-src@afd91fb SOAP > . SoapClient::$httpurl is now a Soap\Url object rather than a resource. > Checks using is_resource() (i.e. is_resource($client->httpurl)) should be > replaced with checks for null (i.e. $client->httpurl !== null). > . SoapClient::$sdl is now a Soap\Sdl object rather than a resource. > Checks using is_resource() (i.e. is_resource($client->sdl)) should be > replaced with checks for null (i.e. $client->sdl !== null). Refs: * https://github.com/php/php-src/blob/e1c8329b8ca9222f7a5f48c1ca19e95129b807c0/UPGRADING#L156-L161 * php/php-src 14121 * php/php-src@44b3cb2 * php/php-src@44b3cb2 --- PHP 8.4 resource to object migrations not included in this commit COM This conversion appears to be internal only and has no impact on userland.
…t conversion There are on-going efforts to remove the use of resources and change these to opaque (final, non-serializable, non-constructable) objects. This commit addresses detection of the use of these new classes introduced as part of these efforts in PHP 8.4. As these classes are all namespaced and reserve additional top-level namespaces for PHP, the `Namespaces\ReservedNames` sniff has also been updated. :point_right: Note: There is currently no sniff which examines how the return value of the affected function calls is handled. This could possible be added at some point in the future, though would be complicated, what with the many ways in which the return value could be checked. Related to 1731 Refs: * php/php-tasks#6 * https://wiki.php.net/rfc/resource_to_object_conversion What's addressed in this commit DBA > . dba_open() and dba_popen() will now return a Dba\Connection > object rather than a resource. Return value checks using is_resource() > should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/0f8259e896dd609aa9f5a8274ead17d81185a45c/UPGRADING#L48-L51 * php/php-src 14329 * php/php-src@2097237 ODBC > . odbc_connect() and odbc_pconnect() will now return an Odbc\Connection > object rather than a resource. Return value checks using is_resource() > should be replaced with checks for `false`. > . odbc_prepare(), odbc_exec(), and various other functions will now return > an Odbc\Result object rather than a resource. Return value checks using > is_resource() should be replaced with checks for `false`. Refs: * https://github.com/php/php-src/blob/e1c8329b8ca9222f7a5f48c1ca19e95129b807c0/UPGRADING#L86-L91 * php/php-src 12040 * php/php-src@afd91fb SOAP > . SoapClient::$httpurl is now a Soap\Url object rather than a resource. > Checks using is_resource() (i.e. is_resource($client->httpurl)) should be > replaced with checks for null (i.e. $client->httpurl !== null). > . SoapClient::$sdl is now a Soap\Sdl object rather than a resource. > Checks using is_resource() (i.e. is_resource($client->sdl)) should be > replaced with checks for null (i.e. $client->sdl !== null). Refs: * https://github.com/php/php-src/blob/e1c8329b8ca9222f7a5f48c1ca19e95129b807c0/UPGRADING#L156-L161 * php/php-src 14121 * php/php-src@44b3cb2 * php/php-src@60336de --- PHP 8.4 resource to object migrations not included in this commit COM This conversion appears to be internal only and has no impact on userland.
A long term project is to move all extension resources to objects as they are all in all better.
This issue aims to list the remaining usages of resources within php-src
Related RFC: https://wiki.php.net/rfc/resource_to_object_conversion
PHP 8.0:
PHP 8.1:
Scheduled for PHP 8.4:
Scheduled for PHP 9.0:
Remaining:
Persistent resources that are only used internally and not exposed to userland:
The text was updated successfully, but these errors were encountered: