|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-11-20 13:55 UTC] matej21 at matej21 dot cz
Description:
------------
When you check if private/protected constant is defined on a class, it currently triggers a fatal error.
For a consistency with method_exists and property_exists it should probably ignore visibility and return true
Test script:
---------------
<?php
class Foo
{
private const BAR = 1;
}
var_dump(defined('Foo::BAR'));
Expected result:
----------------
bool(true)
Actual result:
--------------
Fatal error: Uncaught Error: Cannot access private const Foo::BAR
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 05:00:01 2026 UTC |
you still compare different things here and for consistency they all should return false outside of the context $this because it's simply wrong behavior leading to errors like this one which couldn't work beause for the current scope it don't exist if(property_exists($foo, 'bar'))) { $foo->bar = 10; } _________________________________ $foo = new Foo; var_dump(property_exists($foo, 'bar')); var_dump(method_exists($foo, 'bar')); defined('Foo::BAR'); _________________________________