php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #39615 Exception code can not be string
Submitted: 2006-11-24 11:33 UTC Modified: 2015-06-06 16:08 UTC
Votes:16
Avg. Score:3.8 ± 1.1
Reproduced:13 of 13 (100.0%)
Same Version:4 (30.8%)
Same OS:7 (53.8%)
From: marcos dot neves at gmail dot com Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: * OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-11-24 11:33 UTC] marcos dot neves at gmail dot com

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-04 05:22 UTC] 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.
 [2011-01-01 23:40 UTC] jani@php.net
-Summary: Exception code cant be string +Summary: Exception code can not be string -Package: Feature/Change Request +Package: Scripting Engine problem -Operating System: ANY +Operating System: *
 [2011-04-25 18:41 UTC] 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.
 [2015-06-06 16:08 UTC] cmb@php.net
-PHP Version: 5.2.0 +PHP Version: *
 [2015-06-06 16:08 UTC] 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.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC