rfc:deprecate-json_encode-nonserializable
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:deprecate-json_encode-nonserializable [2024/09/03 10:13] – pilif | rfc:deprecate-json_encode-nonserializable [2024/09/05 10:00] (current) – more detailed analysis of affected classes. Info about workaround for classes with public fields. pilif | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Deprecate json_encode() on classes marked as non-serializable ====== | ====== PHP RFC: Deprecate json_encode() on classes marked as non-serializable ====== | ||
- | * Version: 0.9 | + | * Version: 0.11 |
- | * Date: 2024-09-03 | + | * Date: 2024-09-05 |
* Author: Philip Hofstetter, phofstetter@sensational.ch | * Author: Philip Hofstetter, phofstetter@sensational.ch | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 15: | Line 15: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes to mark calling < | + | This RFC proposes to mark calling < |
The flag '' | The flag '' | ||
Line 23: | Line 23: | ||
For temporary resources (file handles, etc.) this is potentially an acceptable behavior, albeit a bit inconsistent to how serialization is handled, but for < | For temporary resources (file handles, etc.) this is potentially an acceptable behavior, albeit a bit inconsistent to how serialization is handled, but for < | ||
- | This can be done mostly transparently to the rest of the code-base, but will require special handling for a potential < | + | This can be done mostly transparently to the rest of the code-base, but will require special handling for a potential < |
+ | One exception to the rule is anonymous classes which are all marked as '' | ||
+ | |||
+ | In case of < | ||
+ | |||
+ | Thus, this RFC proposes to continue to permit < | ||
==== Other options considered ==== | ==== Other options considered ==== | ||
Line 35: | Line 40: | ||
- Have < | - Have < | ||
- Have < | - Have < | ||
+ | |||
+ | ==== Impacted internal classes ==== | ||
+ | |||
+ | At the time of writing this RFC, the following list of classes (and their subclasses) are affected by this RFC and calling < | ||
+ | |||
+ | Some of those are containers of a sort, where this encoding is especially misleading (aside of < | ||
+ | |||
+ | Most of the non-serializable classes have no public properties and thus encode as '' | ||
+ | |||
+ | Those which currently do have public properties are still mostly meant for internal usage and thus not ideal candidates to < | ||
+ | |||
+ | <code php> | ||
+ | $a = new SimpleXmlElement('< | ||
+ | echo json_encode($a); | ||
+ | echo json_enode((array) $a); // {" | ||
+ | </ | ||
+ | |||
+ | === Classes with public fields appearing in json_encode() output === | ||
+ | * CURLFile (has three public properties) | ||
+ | * PDORow (has one public property, queryString) | ||
+ | * PDOStatement (has one public property, queryString) | ||
+ | * SimpleXMLElement (might be useful) | ||
+ | * ReflectionAttribute | ||
+ | * ReflectionClass | ||
+ | * ReflectionClassConstant | ||
+ | * ReflectionConstant | ||
+ | * ReflectionExtension | ||
+ | * ReflectionFiber | ||
+ | * ReflectionFunctionAbstract | ||
+ | * ReflectionGenerator | ||
+ | * ReflectionParameter | ||
+ | * ReflectionProperty | ||
+ | * ReflectionReference | ||
+ | * ReflectionType | ||
+ | * ReflectionZendExtension | ||
+ | |||
+ | |||
+ | === Backed by temporary resources === | ||
+ | * AddressInfo | ||
+ | * Collator | ||
+ | * CurlHandle | ||
+ | * CurlMultiHandle | ||
+ | * CurlShareHandle | ||
+ | * DOMXPath | ||
+ | * Dba\Connection | ||
+ | * DeflateContext | ||
+ | * Dom\Implementation | ||
+ | * Dom\NamespaceInfo | ||
+ | * Dom\TokenList | ||
+ | * Dom\XPath | ||
+ | * Dom\XMLDocument | ||
+ | * EnchantBroker | ||
+ | * EnchantDictionary | ||
+ | * FFI | ||
+ | * FFI\CData | ||
+ | * FFI\CType | ||
+ | * FTP\Connection | ||
+ | * GdFont | ||
+ | * GdImage | ||
+ | * InflateContext | ||
+ | * IntlBreakIterator | ||
+ | * IntlCalendar | ||
+ | * IntlCodePointBreakIterator | ||
+ | * IntlDateFormatter | ||
+ | * IntlDatePatternGenerator | ||
+ | * IntlIterator | ||
+ | * IntlPartsIterator | ||
+ | * IntlRuleBasedBreakIterator | ||
+ | * IntlTimeZone | ||
+ | * LDAP\Connection | ||
+ | * LDAP\Result | ||
+ | * LDAP\ResultEntry | ||
+ | * MessageFormatter | ||
+ | * NumberFormatter | ||
+ | * Odbc\Connection | ||
+ | * Odbc\Result | ||
+ | * OpenSSLAsymmetricKey | ||
+ | * OpenSSLCertificate | ||
+ | * OpenSSLCertificateSigningRequest | ||
+ | * PDO | ||
+ | * Pdo\Dblib | ||
+ | * Pdo\Firebird | ||
+ | * Pdo\Mysql | ||
+ | * Pdo\Odbc | ||
+ | * Pdo\Pgsql | ||
+ | * Pdo\Sqlite | ||
+ | * PgSql\Connection | ||
+ | * PgSql\Lob | ||
+ | * PgSql\Result | ||
+ | * Random\Engine\Secure | ||
+ | * ResourceBundle | ||
+ | * SQLite3 | ||
+ | * SQLite3Result | ||
+ | * SQLite3Stmt | ||
+ | * Shmop | ||
+ | * Soap\Sdl | ||
+ | * Soap\Url | ||
+ | * Socket | ||
+ | * SplFileInfo | ||
+ | * Spoofchecker | ||
+ | * SysvMessageQueue | ||
+ | * SysvSemaphore | ||
+ | * SysvSharedMemory | ||
+ | * Transliterator | ||
+ | * UConverter | ||
+ | * XMLParser | ||
+ | * finfo | ||
+ | * variant | ||
+ | |||
+ | === Other === | ||
+ | * Closure | ||
+ | * Fiber | ||
+ | * Generator | ||
+ | * InternalIterator | ||
+ | * SensitiveParameterValue | ||
+ | * WeakMap | ||
+ | * WeakReference | ||
+ | |||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 72: | Line 195: | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
+ | https:// | ||
===== Implementation ===== | ===== Implementation ===== |
rfc/deprecate-json_encode-nonserializable.1725358395.txt.gz · Last modified: 2024/09/03 10:13 by pilif