php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80234 user-defined error handler and string numeric keys in $errcontext
Submitted: 2020-10-14 11:36 UTC Modified: 2021-08-24 12:20 UTC
From: david at grudl dot com Assigned:
Status: Open Package: Scripting Engine problem
PHP Version: 7.4.11 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2020-10-14 11:36 UTC] david at grudl dot com
Description:
------------
Array $context passed to custom error handler is non-standard because contains string numeric keys. Example: https://3v4l.org/BR04H


Because $context is deprecated, there is no need to fix it, I just wanted to document it.

Test script:
---------------
<?php

set_error_handler(function ($errno, $errstr, $errfile, $errline, $errcontext) {
	var_dump($context);
});

$a = 1;
$$a = 2;


Expected result:
----------------
array(3) { [1]=> int(2), ... }

Actual result:
--------------
array(3) { ["1"]=> int(2), ... }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-24 12:20 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem
 [2021-08-24 12:20 UTC] cmb@php.net
> Array $context passed to custom error handler is non-standard
> because contains string numeric keys.

Well, get_defined_vars() has the same behavior[1] (and maybe
others as well), and generally this may happen when casting
objects to array prior to PHP 7.2.0[2].  It might be worthwhile to
address the future scope section of the respective RFC[3], but I'm
changing to doc problem for now.

[1] <https://3v4l.org/Z1YPI>
[2] <https://www.php.net/manual/en/language.types.object.php#language.types.object.casting>
[3] <https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts#future_scope>
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Oct 17 04:03:34 2021 UTC