php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #12596 Definition of array using constants in array doesn't work
Submitted: 2001-08-06 09:41 UTC Modified: 2001-10-21 20:07 UTC
From: jack at mobil dot cz Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.0.5 OS: Linux
Private report: No CVE-ID: None
 [2001-08-06 09:41 UTC] jack at mobil dot cz
The following piece of code doesn't work:

<?
    define ('A', 20);

    class B
    {
	var $a = array(A => 10);
    }

    $b = new B();
    var_dump($b);
?>

It produces:

object(b)(1) {
  ["a"]=>
  array(1) {
    ["A"]=>
    int(10)
  }
}

which is unexpected (at least for me).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-08-06 15:27 UTC] jeroen@php.net
This isn't supposed to work (class-var initing is not allowed for non-scalar (for example array) values).

It is funny that it turns out to work this way, a parse-error would be better IMO.

But it is not a bug, changing status to feedback.

It is in the manual somewhere that this isn't allowed, try language -> classes and object
 [2001-10-02 18:34 UTC] sniper@php.net
Not a bug -> Bogus.
 [2001-10-02 19:52 UTC] jeroen@php.net
It _is_ strange that no parse error is given. I think it should.

So IMO the bug is that it seems to work a bit, but doesn't. Either support this, or give parse error. 

I see no reason to not support a random expression though... that expression-opcodes should internally be moved to class initialization. Since PHP 4 doesn't have a real constructor, this won't be realizable until ZE 2 I think.

Status->Suspended
 [2001-10-21 20:07 UTC] sniper@php.net
Seems to work with PHP 4.1.0RC1:

object(b)(1) {
  ["a"]=>
  array(1) {
    [20]=>
    int(10)
  }
}

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC