Category
stdlib · php-src-strict · SimpleXML scalar cast (pillar 4 / live-node adjacent)
Problem
Zend sxe_object_cast_ex treats a present element as boolean true even when its text is empty or "0". Only a missing/blank node property is false. After $z = $xml->missing, empty($z) is true on Zend.
VM (bool) follows ordinary string-truthiness of the text content (empty/"0" → false), and empty($z) after assigning a missing child is false.
Distinct from #19707 (empty($xml->child) property-fetch path — already green for empty($xml->z)).
Probed 2026-07-23 on master VM vs host Zend 8.2.32 (./script/docker-exec.sh). Use parentheses: (bool)($xml->a) (cast binds tighter than ->).
Repro ($xml = simplexml_load_string('<r><a/><b>0</b><d>x</d></r>')) |
Zend 8.2+ |
VM (2026-07-23) |
(bool)($xml->a) empty element |
true |
false |
(bool)($xml->b) text "0" |
true |
false |
(bool)($xml->d) text "x" |
true |
true |
(bool)($xml->z) missing |
false |
false |
$z=$xml->z; empty($z) |
true |
false |
php-src reference
PHP implementation target
lib/VM/Variable.php (toBool) and/or ext/simplexml/VmSimpleXml.php — SimpleXMLElement object cast to bool per sxe_object_cast_ex (present element ⇒ true; blank/missing ⇒ false)
- Ensure
empty($sxeVar) on an assigned missing-child view matches Zend (related blank-node check)
- JIT/AOT object-cast lowering must share the same rule; no new
runtime/*.c logic
Repro
./script/docker-exec.sh -- bash -lc 'cat > /tmp/sxe_bool.php <<'\''PHP'\''
<?php
$xml=simplexml_load_string("<r><a/><b>0</b></r>");
var_export((bool)($xml->a)); echo "\n";
var_export((bool)($xml->b)); echo "\n";
$z=$xml->z; var_export(empty($z)); echo "\n";
PHP
php /tmp/sxe_bool.php; php bin/vm.php /tmp/sxe_bool.php'
Done when
Category
stdlib· php-src-strict · SimpleXML scalar cast (pillar 4 / live-node adjacent)Problem
Zend
sxe_object_cast_extreats a present element as boolean true even when its text is empty or"0". Only a missing/blank node property is false. After$z = $xml->missing,empty($z)is true on Zend.VM
(bool)follows ordinary string-truthiness of the text content (empty/"0"→ false), andempty($z)after assigning a missing child is false.Distinct from #19707 (
empty($xml->child)property-fetch path — already green forempty($xml->z)).Probed 2026-07-23 on master VM vs host Zend 8.2.32 (
./script/docker-exec.sh). Use parentheses:(bool)($xml->a)(cast binds tighter than->).$xml = simplexml_load_string('<r><a/><b>0</b><d>x</d></r>'))(bool)($xml->a)empty elementtruefalse(bool)($xml->b)text"0"truefalse(bool)($xml->d)text"x"truetrue(bool)($xml->z)missingfalsefalse$z=$xml->z; empty($z)truefalsephp-src reference
ext/simplexml/simplexml.c—sxe_object_cast_ex(IS_FALSE/IS_TRUE/_IS_BOOL)empty()on an already-fetched SimpleXMLElementPHP implementation target
lib/VM/Variable.php(toBool) and/orext/simplexml/VmSimpleXml.php— SimpleXMLElement object cast to bool persxe_object_cast_ex(present element ⇒ true; blank/missing ⇒ false)empty($sxeVar)on an assigned missing-child view matches Zend (related blank-node check)runtime/*.clogicRepro
Done when
.phptundertest/compliance/cases/simplexml/