什么是职业年金| 琛读什么| 5月1日什么星座| 尿蛋白高有什么危害| 怀孕吸烟对胎儿有什么影响| 撤退性出血是什么颜色| 肩膀酸痛是什么原因| 安利是什么意思| 爱被蚊子咬是什么体质| 石龙子吃什么| 白细胞数目偏高是什么意思| 津液不足吃什么中成药| 身份证上的数字是什么字体| 大汗淋漓是什么意思| 腹痛拉肚子吃什么药| 办理暂住证需要什么材料| 怀孕白细胞高是什么原因| 为什么会胃酸反流| 脚后跟干裂起硬皮用什么药| 生物工程专业学什么| 脑萎缩吃什么药能控制| 庆字五行属什么| 气血虚吃什么补最快女人| 三个火念什么| 梦见好多鱼是什么意思| 做鸡蛋饼用什么面粉好| 牛和什么属相最配| 乌灵参是什么东西| 单核细胞是什么意思| bn是什么意思| 中国最长的河是什么河| 打日本电话前面加什么| 什么是直男| 月经咖啡色是什么原因| 脂蛋白a是什么| 草朋刀是什么字| 长寿面什么时候吃| 狮子座和什么座最配| 黑热病是什么病| 吃什么皮肤变白| 水火既济是什么意思| 什么季节最短| 萩是什么意思| 忌诸事不宜是什么意思| 梦见经血是什么预兆| 黄飞鸿代表什么生肖| 漫展是干什么的| 炎细胞是什么意思| 眼睛皮痒是什么原因| 提上日程是什么意思| 粉色裤子配什么上衣| 为什么不一样| 青霉素主治什么病| 性疾病都有什么症状| 钙片什么时候吃| 后背酸疼是什么原因| 什么什么迷人| 酒干倘卖无什么意思| 唾液有臭味是什么原因| 当志愿者有什么好处| 请示是什么意思| la是什么| 钠尿肽高是什么原因| 6月29日什么星座| 马齿菜有什么功效| 梦见下大雨是什么征兆| 半夜醒来口干舌燥是什么原因| 金针菇炒什么好吃| 六畜大宝在农家是什么生肖| 刘华强是什么电视剧| 梦见吃排骨是什么意思| 什么是认证| 油边是什么肉| 下午5点半是什么时辰| 什么是圣人| 黄瓜是绿色的为什么叫黄瓜| 什么是射精| 超声波是什么意思| saa偏高说明什么| 木瓜什么味道| 经常头疼什么原因| 梦见初恋男友是什么意思| 什么是业障| 元胡是什么| 软笔是什么| 头疼发烧吃什么药| 什么的宝石| 尺码m是什么意思| 免疫什么意思| 为什么月经量少| 食管裂孔疝是什么意思| 入伏吃羊肉有什么好处| 二手房是什么意思| 脑梗是什么症状| 鼠入牛角是什么动物| 梗米是什么| 女人有腰窝意味着什么| 做颈动脉彩超挂什么科| 一什么孩子| 囊肿是什么原因造成的| suan是什么意思| 火象是什么星座| 但求无愧于心上句是什么| modern是什么牌子| 兄弟左右来是什么生肖| 小儿风寒感冒吃什么药最好| 套话是什么意思| 得了肠息肉有什么症状| 构筑物是什么意思| 诺迪康胶囊治什么病| 蛋白粉吃了有什么好处| ib是什么单位| 性格好是什么意思| 胆囊炎需要注意什么| 液基薄层细胞学检查是什么| 低血钾吃什么补上来的快| o型阴性血是什么意思| 天蝎和什么星座最配| 尾盘跳水意味着什么| 吃什么可以补精| 椰子鞋是什么牌子| fc什么意思| 雪莲菌泡牛奶有什么功效| 潘多拉魔盒是什么意思| 挂失补办身份证需要什么| 祈禳是什么意思| 麻雀吃什么| reed是什么意思| 怀孕什么时候吃鹅蛋最好| 比熊吃什么牌子狗粮好| 苦衷是什么意思| 步长是什么意思| 血糖和尿糖有什么区别| 暴露是什么意思| 微不足道什么意思| 心脏属于什么组织| 7月5号是什么星座| 囗苦是什么原因| 今天买什么股票| 甲功三项查的是什么| 鸡毛换糖是什么意思| 贡中毒有什么症状| 爸爸的爸爸叫什么| 贵州有什么好吃的| 黄五行属什么| 梦见自己牙齿掉光了是什么征兆| dc是什么牌子| 怀孕什么东西不能吃| 西游记告诉我们什么道理| 吃什么菜| 被利用的信任是什么歌| 刘邦为什么杀韩信| 车水马龙是什么生肖| 发泡实验阳性说明什么| 双肾钙化灶是什么意思| 换手率高说明什么| 细菌感染发烧吃什么药| 地狱不空誓不成佛是什么意思| 属鸡的女生和什么属相最配| 眼底照相是检查什么| 一什么边| 一直放臭屁是什么原因| 梦到结婚是什么预兆| 痛风可以吃什么肉| 腹部疼挂什么科| 超级碗是什么比赛| 色素沉着有什么办法可以去除| 屎壳郎是什么意思| 癣用什么药膏| 世界屋脊指的是什么| 蒙古族不吃什么肉| 肉蔻是什么样子| 死胎有什么症状| 无底洞是什么意思| 瑞夫泰格手表什么档次| polo是什么意思| 一见钟情是什么感觉| 长湿疹是什么原因引起的| 巨蟹男喜欢什么类型的女生| 股骨长径是指胎儿什么| 什么是一线城市| 之虞是什么意思| 英国为什么要脱欧| 肚子一按就痛什么原因| 维生素c阴性什么意思| 乳房看什么科| 天麻有什么功效| 中度贫血吃什么补血快| qs认证是什么意思| 什么样的女人水多| 小径是什么意思| 卡蒂罗属于什么档次| 长脸适合什么发型男| 女生排卵期在什么时候| 三楼属于五行属什么| 关帝是什么神| 盆腔积液吃什么药效果好| 什么能软化血管| 枸杞对女人有什么好处| 月经迟迟不来是什么原因| 腹膜刺激征是指什么| 极光是什么意思| 面色无华什么意思| 春回大地是什么生肖| 百合什么意思| 卑职是什么意思| 花椒有什么作用| 女性得疱疹是什么症状| 孕妇吃什么长胎不长肉| 平舌音是什么意思| 7月23号是什么星座| 结甲是什么意思| 肚子大什么原因| 什么是嗳气有何症状| 没有舌苔是什么原因| 大姨父是什么意思| 芒果不可以跟什么一起吃| 山竹是什么季节的水果| 突然想吐是什么原因| 豆浆什么人不能喝| 绝非偶然是什么意思| 儿童坐飞机需要带什么证件| 高血压应该吃什么| 四月三日是什么星座| 腹痛腹泻吃什么药| 尿素酶阳性什么意思| 玉米和什么不能一起吃| 水猴子长什么样| 鲐背之年是什么意思| 为什么美国支持以色列| 和胃降逆是什么意思| 女流之辈是什么意思| 1月什么星座| 胃炎挂什么科| 红豆有什么功效和作用| 16什么意思| 英雄难过美人关是什么生肖| 梦到数钱代表什么预兆| 什么清什么楚| 伟哥是什么| 头顶长白头发是什么原因造成的| 胃火旺喝什么茶| 不以为意什么意思| 恍然大悟什么意思| 柔软的什么| 汉朝后面是什么朝代| 柠檬吃多了有什么坏处| 好整以暇什么意思| 江诗丹顿属于什么档次| 梦到抓鱼是什么意思| 揽子是什么意思| 秋葵对痛风有什么好处| 45年属什么| 腹泻便溏是什么意思| 什么地唱| 什么是吸附性义齿| 夏天哈尔滨有什么好玩的地方| 甲亢什么不能吃| 直女是什么意思| 切尔西是什么意思| 超拔是什么意思| 为什么硬不起来| 吃什么补锌| 准备好了吗时刻准备着是什么歌| 百度
rfc:deprecate-json_encode-nonserializable

胎心停了是什么原因引起的

Introduction

百度 而在现行规定下,互联网公司只需在其总部所在地一次性交税。

PHP internally marks some classes as not fit for serialization using a flag ZEND_ACC_NOT_SERIALIZABLE which prevents instances of such classes from being serialized using serialize().

However, this flag is currently not respected by json_encode() which is another serialization method built into PHP and which has special support by the language for userland through JsonSerializable. json_encode() will encode all instances of internal classes as {} regardless of serializabiliy.

Especially for Generator this is harmful because converting a pre-computed array into a lazy iterator using Generator is a useful and relatively common refactoring which can otherwise be done transparently to a code-base. At that point it's inconvenient that json_encode() silently encodes Generator instances as {}, changing its shame and contents.

Proposal

This RFC proposes to mark calling json_encode() on most instances of classes marked with ZEND_ACC_NOT_SERIALIZABLE as deprecated with the longer-term option of throwing an error in the next major version of PHP wich will follow the one this RFC is implemented in.

The flag ZEND_ACC_NOT_SERIALIZABLE was intended to mark classes as non-serializable because they either represent a temporary local resource (like a file or database handle) which could not possibly be unserialized later on or because serializing them could have large side-effects (in case of Generator and Iterator).

The same reasoning applies to json_encode() which right now doesn't invoke any of the side-effects (good) but also silently encodes any such object instance as {}.

For temporary resources (file handles, etc.) this is potentially an acceptable behavior, albeit a bit inconsistent to how serialization is handled, but for Generator, doing this silently is very inconvenient for a developer in the process of converting a code-base from pre-built arrays to generators for either performance or memory consumption reasons.

This can be done mostly transparently to the rest of the code-base, but will require special handling for a potential json_encode() which will currently silently does the wrong thing and not just skip iterating the generator but will also silently change the shape of the output, potentially breaking API contracts without any notification to the user.

One exception to the rule is anonymous classes which are all marked as ZEND_ACC_NOT_SERIALIZABLE because then unserializing, their definition will not be present, so they cannot possibly be unserialized again.

In case of json_encode() though, where no generic unserialize operation is defined anyways, there's no reason for deprecating or forbidding to json_encode() anonymous classes, unless their parent class is marked as ZEND_ACC_NOT_SERIALIZABLE where the above reasoning applies again.

Thus, this RFC proposes to continue to permit json_encode() on anonymous classes unless they extend a class marked as ZEND_ACC_NOT_SERIALIZABLE.

Other options considered

This RFC proposes a solution that handles all classes block-listed for serialization to create a consistent behavior beteween the two built-into PHP serialization mechanisms.

Other options considered concern themselves with handling just the Generator case:

  1. Add a special case to deprecate/disallow JSON encoding of Generator, but otherwise not look at ZEND_ACC_NOT_SERIALIZABLE. This would be a proposed fallback option if the backwards compatility concerns are too large to consider. It would complicate the implementation consierably.
  2. Have json_encode() consume the generator and recurse as if it was encoding an array. While this would probably be the most ergonomic solution for the refactoring case outlined above, given the unforeseeable side-effects generator consumption can have, including endless loops, this is a dangerous operations and whas thus discarded as an option.
  3. Have json_encode() encode generators as []: This would help the refactoring case by upholding possible API contracts and would more cleanly match the shape of a generator (which is a list after all), but it would also be lying to the calling code because the generator likely won't be empty.

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 json_encode() on them will throw a deprecation warning in the future.

Some of those are containers of a sort, where this encoding is especially misleading (aside of Generator which was the motivator for this RFC, WeakMap stands out specifically).

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 json_encode() them. However, if code wants to explicitly turn any such instances into JSON in light of the deprecation currently proposed, casting such instances into array before JSON encoding them is a valid workaround.

$a = new SimpleXmlElement('<a><b>3</b><c>foo</c></a>');
echo json_encode($a); // {"b":"3","c":"foo"}, with deprecation warning
echo json_enode((array) $a); // {"b":"3","c":"foo"}, no deprecation warning

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

Code which accidentally runs json_encode() over instances of classes marked as non-serializable or over larger structures which contain such instances will cause a deprecation warning to be thrown when before there wasn't.

Given that the encoded output was mostly useless for any consumer of such JSON and given that producing the previous output manually is not hard, it's the belief of this RFC that the deprecation warning provides more value than the current behavior because current invocations of json_encode() over unserialized classes is likely unintentional (given the current output of json_encode()).

Proposed PHP Version(s)

PHP 8.5

RFC Impact

To SAPIs

The deprecation warning will bre raised in all SAPIs

To Existing Extensions

None

To Opcache

None

Ran the included test-case in the PR with Opcache enabled and got the expected result.

New Constants

None

Open Issues

None

Unaffected PHP Functionality

Any other argument to json_encode() is unaffected

Future Scope

In the next major version after this RFC passes, the deprecation warning can be changed to an Error, though this will be part of a separate RFC.

Proposed Voting Choices

Should calling json_encode() on instances of classes marked with ZEND_ACC_NOT_SERIALIZABLE be marked as deprecated? Yes, No?

Patches and Tests

Implementation

References

rfc/deprecate-json_encode-nonserializable.txt · Last modified: by 127.0.0.1

?
门户网站是什么 pq是什么意思 尿糖弱阳性是什么意思 经常按摩头皮有什么好处 高血糖适合吃什么主食
火箭军是干什么的 聤耳是什么意思 青金石五行属什么 母亲节要送什么礼物 人为什么会便秘
4月30号是什么星座 贝母和川贝有什么区别 一什么车厢 车震是什么意思 一竖读什么
指甲很薄很软是为什么 什么店可以买到老鼠药 拿乔是什么意思 傀儡什么意思 凝血五项是检查什么病
吃什么可以修复子宫内膜hkuteam.com 籽字五行属什么hcv8jop1ns9r.cn 什么是平板电脑hcv7jop5ns3r.cn 为什么有mmeoe.com 起什么网名好听travellingsim.com
姜汁洗头发有什么好处hcv8jop9ns5r.cn 小儿疳积是什么意思hcv9jop5ns3r.cn 割包皮是什么hcv9jop5ns0r.cn 苦杏仁味是什么中毒tiangongnft.com 仁义道德是什么意思hcv8jop6ns8r.cn
孕反应最早什么时候开始hcv9jop5ns0r.cn 凌乱是什么意思hcv8jop2ns2r.cn 小娇妻是什么意思hcv7jop6ns3r.cn tct什么意思tiangongnft.com 什么药降肌酐hcv8jop7ns0r.cn
人天是什么意思hcv7jop6ns1r.cn 樟脑是什么东西hcv7jop6ns2r.cn hsv是什么hcv9jop3ns0r.cn 加盟店是什么意思hcv9jop7ns2r.cn 1964属什么hcv9jop7ns4r.cn
百度