Req #48442 [Opn->Fbk]: strpos does not attempt to cast needle as string if needle is an object

From: Date: Wed, 30 Apr 2014 22:45:58 +0000
Subject: Req #48442 [Opn->Fbk]: strpos does not attempt to cast needle as string if needle is an object
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185531@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=48442&edit=1 ID: 48442 Updated by: levim@php.net Reported by: deadowlsurvivor at gmail dot com Summary: strpos does not attempt to cast needle as string if needle is an object -Status: Open +Status: Feedback Type: Feature/Change Request -Package: Feature/Change Request +Package: *General Issues -Operating System: Ubuntu Linux +Operating System: Irrelevant -PHP Version: 5.2.9 +PHP Version: Any Block user comment: N Private report: N New Comment: Is this something you are still interested in seeing? Personally this looks nonsensical; objects aren't integers and so you need to do any conversion yourself. Previous Comments: ------------------------------------------------------------------------ [2009-06-01 00:50:16] deadowlsurvivor at gmail dot com Description: ------------ Currently, if you attempt to set Reproduce code: --------------- class foo { private $bar; public function __construct($bar) { $this->bar = $bar; } public function __toString() { return $bar; } } $a = new foo('abc'); $b = new foo('ab'); $pos = strpos($a,$b); Expected result: ---------------- $pos holds the value of 0. Actual result: -------------- While $a is cast to a string, PHP attempts to cast $b into an integer, as documented. However, wouldn't it make sense to attempt to cast $b into a string if casting it as an integer fails? Or even to attempt to cast it into a string first? ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=48442&edit=1

« previous php.bugs (#185531) next »