php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66034 defined not working on traits
Submitted: 2013-11-05 09:59 UTC Modified: 2013-11-05 13:46 UTC
From: karibou at ribouka dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 5.4.21 OS: debian
Private report: No CVE-ID: None
 [2013-11-05 09:59 UTC] karibou at ribouka dot com
Description:
------------
I'm on 5.4.14
I won't upgrade to test this, if someone have 5.4.21, can he tests and reports.

If you call a constant of a class in a trait (of that class), it works.

BUT, if you want to test its existence by 'defined' it's always return false.



Test script:
---------------
class MyClass{

  use MyTrait;
  const MY_CONST = 'TEST';

}

Trait MyTrait{
  public function testConst()
  {
    echo self::MY_CONST;
    var_dump(defined(self::MY_CONST));
  }
}

$myClass = new MyClass();
$myClass->testConst();

Expected result:
----------------
Test
boolean true

Actual result:
--------------
Test
boolean false

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-05 10:02 UTC] karibou at ribouka dot com
In expected and actuel result, i mistype 'TEST' by 'Test'. :)
 [2013-11-05 13:46 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2013-11-05 13:46 UTC] laruence@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

your test is wrong, you should:

var_dump(defined("self::MY_CONST")); // notice the quotes
 [2013-11-09 10:21 UTC] ab@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e3d9e18e7b24ba2d5c9e420510e804330c94f955
Log: Fixed Bug #66034 (Segmentation Fault when constructor of PDO statement throws an exception)
 [2013-11-09 10:21 UTC] ab@php.net
-Status: Not a bug +Status: Closed
 [2014-10-07 23:16 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=e3d9e18e7b24ba2d5c9e420510e804330c94f955
Log: Fixed Bug #66034 (Segmentation Fault when constructor of PDO statement throws an exception)
 [2014-10-07 23:27 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=e3d9e18e7b24ba2d5c9e420510e804330c94f955
Log: Fixed Bug #66034 (Segmentation Fault when constructor of PDO statement throws an exception)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 19:01:30 2024 UTC