Bug #80659 [Opn]: unexp. Typecast at not fitting function return type declaration
| From: | thomas dot bindewald at metanet dot ch | Date: | Fri, 22 Jan 2021 10:24:35 +0000 |
| Subject: | Bug #80659 [Opn]: unexp. Typecast at not fitting function return type declaration | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231701@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80659&edit=1
ID: 80659
User updated by: thomas dot bindewald at metanet dot ch
Reported by: thomas dot bindewald at metanet dot ch
Summary: unexp. Typecast at not fitting function return type
declaration
Status: Open
Type: Bug
Package: Class/Object related
Operating System: Linux 4.19.0-13-amd64 x86_64 GNU
PHP Version: 8.0.1
Block user comment: N
Private report: N
New Comment:
There could be discussed, if returning the SimpleXMLElement would be okay, as the return type
declaration allows "stdClass" (?).
But a silent "empty string"-conversion/casting is definitely unexpected.
Previous Comments:
------------------------------------------------------------------------
[2021-01-22 09:54:06] thomas dot bindewald at metanet dot ch
Description:
------------
Environment: Debian 10 Linux
PHP-Packages from https://packages.sury.org/php/
---
PHP 8.0.1 (cli) (built: Jan 12 2021 13:59:46) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.1, Copyright (c) Zend Technologies
with Zend OPcache v8.0.1, Copyright (c), by Zend Technologies
with Xdebug v3.0.1, Copyright (c) 2002-2020, by Derick Rethans
Test script:
---------------
<?php
âfunction foooo() : false|string|stdClass {
$xmlString =
'<xml><woche><Montag>Erdbeermarmelade</Montag><Dienstag>Lindenbluetenhonig</Dienstag></woche></xml>';
$xmlObj = new SimpleXMLElement($xmlString);
var_dump($xmlObj);
return $xmlObj;
}
â$wert = foooo();
var_dump($wert);
exit;
Expected result:
----------------
TypeError Exception being thrown.
Actual result:
--------------
XML-Object silently being casted to empty string.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80659&edit=1