php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45765 ReflectionObject with default parameters of self::xxx cause an error.
Submitted: 2008-08-08 15:16 UTC Modified: 2008-08-11 00:50 UTC
From: RQuadling at GMail dot com Assigned: felipe (profile)
Status: Closed Package: Reflection related
PHP Version: 5.2CVS, 5.3CVS, 6CVS OS: Windows XP SP2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: RQuadling at GMail dot com
New email:
PHP Version: OS:

 

 [2008-08-08 15:16 UTC] RQuadling at GMail dot com
Description:
------------
If you have a method with a parameter whose default is a local class constant, the ReflectionObject throws a Fatal Error.

Reproduce code:
---------------
<?php
class foo {
 const BAR = "foo's bar";

 function test ($s_Text = self::BAR) {
  echo $s_Text, PHP_EOL;
 }

}

$o_Foo = new foo();

ReflectionObject::export($o_Foo);

Expected result:
----------------
Object of class [ <user> class foo ] {
  @@ C:\tr.php 2-9

  - Constants [1] {
    Constant [ string BAR ] { foo's bar }
  }

  - Static properties [0] {
  }

  - Static methods [0] {
  }

  - Properties [0] {
  }

  - Dynamic properties [0] {
  }

  - Methods [1] {
    Method [ <user> public method test ] {
      @@ C:\tr.php 5 - 7

      - Parameters [1] {
        Parameter #0 [ <optional> $s_Text = self::BAR]
      }
    }
  }
}

Actual result:
--------------
Fatal error: Undefined class constant 'self::BAR' in C:\tr.php on line 13

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-08 15:18 UTC] RQuadling at GMail dot com
If I change the default to a string, the output is (and I just noticed that it is truncated) ...

Object of class [ <user> class foo ] {
  @@ C:\tr.php 2-9

  - Constants [1] {
    Constant [ string BAR ] { foo's bar }
  }

  - Static properties [0] {
  }

  - Static methods [0] {
  }

  - Properties [0] {
  }

  - Dynamic properties [0] {
  }

  - Methods [1] {
    Method [ <user> public method test ] {
      @@ C:\tr.php 5 - 7

      - Parameters [1] {
        Parameter #0 [ <optional> $s_Text = 'Replaced self::...' ]
      }
    }
  }
}
 [2008-08-08 19:54 UTC] felipe@php.net
Dmitry, I guess it is due the last changes with constants.
 [2008-08-10 23:51 UTC] felipe@php.net
It's also reproducible on 5_2, then not related with last changes.
 [2008-08-11 00:50 UTC] felipe@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

Fixed in 5.2, 5.3 and HEAD.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 14:01:29 2024 UTC