Mantis - Quercus
Viewing Issue Advanced Details
3898 minor always 02-20-10 13:28 03-29-13 00:26
syndetic  
nam  
normal  
closed 4.0.3  
fixed  
none    
none 4.0.36  
0003898: Quercus PHP does not understand Java enums
A PHP script running atop the Quercus engine does not appear to be able to properly understand Java enums.

Example:

== Java ================
public class Foo
{
   public enum Bar { BAZ, QUUX }
}
========================


== PHP =================
import Foo;
foreach(Foo->Bar AS $bar) { echo $bar; } // doesn't work
foreach(Foo::Bar AS $bar) { ... } // doesn't work
foreach(Foo->Bar->values() AS $bar) { ... } // doesn't work
$foo = new Foo();
foreach($foo->Bar AS $bar) { ... } // doesn't work
foreach($foo::Bar AS $bar) { ... } // doesn't work
import Foo->Bar; // no
import Foo::Bar; // still no
echo Foo->Bar->BAZ; // no
echo Foo->Bar::BAZ; // no
echo Foo::Bar->BAZ; // no
========================

Unless my syntax is incorrect, Quercus does not know how to loop over enum values. Depending on how the enum is accessed, sometimes Quercus evaluates the enum itself as a unicode string, which is also wrong. I tried going into the source to find out how it's doing its parsing, but it was just way too much to go through.

Please either indicate the correct way to loop over enum members or else put up a patch somewhere.

Notes
(0004468)
jgritman   
03-14-10 12:59   
I've reproduced this issue as well. I'm trying to prototype Quercus integration with the neo4j graph db but am unable to proceed due to this bug.
(0006231)
nam   
03-29-13 00:26   
php/0cs3
Fixed for 4.0.36.

Java
------------------------------------------
package test;

public class Foo
{
  public enum MyEnum
  {
    A;
    
    public String test()
    {
      return "bar";
    }
  }
}


PHP
------------------------------------------
<?php

import test.Foo;

$a = Foo::MyEnum::A;
var_dump($a);

// note: you'll need to call Enum.values() to get the iterator,
// Quercus currently doesn't automatically call it for you
foreach (Foo::MyEnum->values() as $e) {
  var_dump($e);
}

?>