| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             [2017-03-31 18:03 UTC] peehaa@php.net
 
-Status: Open
+Status: Not a bug
  [2017-03-31 18:03 UTC] peehaa@php.net
  [2017-03-31 18:12 UTC] Andy_Schmidt at HM-Software dot com
  | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 10:00:02 2025 UTC | 
Description: ------------ defined() will function correctly for class constants, if either the class name or a classname variable is used. However, if one tries to check the existence of a constant of the class that was used to instantiate the object, then it will return "not defined". Test script: --------------- class Class_A { const CONST_A = 'value A'; // CONST_B not defined } $class_name = Class_A::class; $object_A = new $class_name(); // Class references work correctly! if ( defined( 'Class_A::CONST_A' ) ) echo 'Class_A::CONST_A defined'; if ( defined( $class_name.'::CONST_A' ) ) echo '$class_name::CONST_A defined'; if ( !defined( 'Class_A::CONST_B' ) ) echo 'No Class_A::CONST_B'; if ( !defined( $class_name.'::CONST_B' ) ) echo 'No $class_name::CONST_B'; echo $object_A::CONST_A; // As expected, result: "value A" ! **** // ***** Yet, using that object reference will report "not" defined! ***** if ( defined( '$object_A::CONST_A' ) ) echo '$object_A::CONST_A defined !!'; else echo 'no $object_A::CONST_A'; // PS: As expected, "Fatal Error: Object of class Class_A could not be converted to string" if ( defined( "$object_A::CONST_A" ) ) echo 'Should cause error, and does'; if ( defined( $object_A.'::CONST_A' ) ) echo 'Should cause error, and does'; Expected result: ---------------- Class_A::CONST_A defined $class_name::CONST_A defined No Class_A::CONST_B No $class_name::CONST_B value A $object_A::CONST_A defined!! Actual result: -------------- Class_A::CONST_A defined $class_name::CONST_A defined No Class_A::CONST_B No $class_name::CONST_B value A no $object_A::CONST_A