php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72920 Accessing a private constant using constant() creates an exception AND warning
Submitted: 2016-08-22 11:27 UTC Modified: -
From: suralc dot github at gmail dot com Assigned:
Status: Closed Package: *General Issues
PHP Version: 7.1.0beta3 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: suralc dot github at gmail dot com
New email:
PHP Version: OS:

 

 [2016-08-22 11:27 UTC] suralc dot github at gmail dot com
Description:
------------
Accessing a private class constant using constant() triggers an exception (as expected) and a warning.

The function should only use one way to report the inaccessible constant; prefferably the Error/Exception. Removing the warning from the constant() function would result in the same behaviour as accessing the constant directly.

A small test script is attached, a slightly larger version is linked here:

https://3v4l.org/JY1AO


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

class Foo {
    private const C1 = "a";
}

try {
    var_dump(constant('Foo::C1'));
} catch(Error $e) {
    echo 'Caught';
}

Expected result:
----------------
Caught

Actual result:
--------------
Warning: constant(): Couldn't find constant Foo::C1 in ??? on line 8
Caught

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-22 15:45 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=434ae90e852ed2b39432baf30d928e26b834c03e
Log: Fixed bug #72920 (Accessing a private constant using constant() creates an exception AND warning)
 [2016-08-22 15:45 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2016-10-17 10:09 UTC] bwoebi@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=434ae90e852ed2b39432baf30d928e26b834c03e
Log: Fixed bug #72920 (Accessing a private constant using constant() creates an exception AND warning)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC