Req #39615 [Com]: Exception code can not be string
Edit report at https://bugs.php.net/bug.php?id=39615&edit=1
ID: 39615
Comment by: corepet696 at geekale dot com
Reported by: marcos dot neves at gmail dot com
Summary: Exception code can not be string
Status: Suspended
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: *
PHP Version: *
Block user comment: N
Private report: N
New Comment:
@cmb what a lame excuse to dodge a bullet, don't you think?
Accessing directly the protected $code to bypass its wrong specification sounds like a bad design
pattern.
RFC, really?
I understand this might be acceptable to PHP programmers since PHP is a garbage language, but
let's be real, it's completely wrong.
Yeah sure lets just clean the dust by hiding under the carpet and move on.
Previous Comments:
------------------------------------------------------------------------
[2021-01-21 14:31:39] cmb@php.net
It makes no sense to leave this unresolved for another five years,
so for the time being, I'm suspending this ticket. If anybody is
still interested in this feature, please pursue the RFC
process[1].
Also note that it is already possible to store *arbitrary* values
in the ::$code property of own exception types[1].
[1] <https://wiki.php.net/rfc/howto>
[2] <https://3v4l.org/KdCAm>
------------------------------------------------------------------------
[2015-06-06 16:08:03] cmb@php.net
> Allowing a non-numeric $code in the Exception constructor seems
> like the right solution.
That might constitute a considerable BC break, and would probably
require an RFC.
------------------------------------------------------------------------
[2015-06-06 14:49:02] cmb@php.net
Related To: Bug #51742
------------------------------------------------------------------------
[2011-04-25 18:41:00] bandy dot chris at gmail dot com
Related to bug 51742.
Allowing a non-numeric $code in the Exception constructor seems like the right solution.
------------------------------------------------------------------------
[2010-08-04 05:22:49] bryan at ravensight dot org
Ubuntu 10.04.1 LTS \n \l
PHP 5.3.2-1ubuntu4.2 with Suhosin-Patch (cli) (built: May 13 2010 20:01:00)
MySQL Server version: 5.1.41-3ubuntu12.5 (Ubuntu)
When executing a statement which generates:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '{REDACTED}' for key
'PRIMARY'
The following test does not pass when the exception is caught:
if ($exception->getCode() === 23000)
However, the following code DOES pass when the exception is caught:
if ((int)$exception->getCode() === 23000)
The API documentation for getCode() states that it returns an integer and that is clearly not the
case in this example.
I merely request that the function and the documentation be consistent.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=39615
--
Edit this bug report at https://bugs.php.net/bug.php?id=39615&edit=1
Thread (6 messages)