Caucho Forums  

This forum is permanently closed because of spam. For free community support, please visit Google Groups:


Go Back   Caucho Forums > Quercus

Reply
 
Thread Tools Display Modes
  #1  
Old 03-20-2011, 03:04 PM
sirpy sirpy is offline
Junior Member
 
Join Date: Mar 2011
Posts: 1
Default Accessing java enums

i have the following enum defined inside a java class X

public static enum AttrType {
D {
private final int value = 1;
public boolean isType(int type) { return (type&this.value)>0; }
public int getValue() {
return value;
}
},
Q {
private final int value = 2;
public boolean isType(int type) { return (type&this.value)>0; }
public int getValue() {
return value;
}
}
}

how do I use it from inside php?i've tried X->AttrType X::AttrType, but without any luck
Reply With Quote
  #2  
Old 03-28-2013, 04:43 PM
zalmolksis zalmolksis is offline
Junior Member
 
Join Date: Mar 2013
Posts: 8
Default the same problem

Hello ! I know it's been two years since you posted that message , but did you find the answer ?
now i have the same problem how to access method from enum
Reply With Quote
  #3  
Old 03-29-2013, 07:54 AM
nam nam is offline
Administrator
 
Join Date: Aug 2009
Posts: 337
Default

Hi guys,

I just fixed this for 4.0.36.

You'll be able to access nested Enum constants using the '::' scope operator. See http://bugs.caucho.com/view.php?id=3898.
Reply With Quote
  #4  
Old 03-29-2013, 10:39 AM
zalmolksis zalmolksis is offline
Junior Member
 
Join Date: Mar 2013
Posts: 8
Post

The problem is a bit different ... the problem is I can't access the methods of enums
exemple:
public enum Gender {
man('strong'), woman('beautifull')

private final String desc;
private Gender(String desc){
this.desc = desc;
}

public String getDesc(){
return desc;
}
}

I have functions that return Gender enums man or woman in php I get string variables and i can't call method getDesc
what I tried :
$enum = java_class('Gender');
import Gender;
var_dump(Gender::man); // resource(man)
var_dump($enum::man); // resource(man)
var_dump(Gender::valueOf('man')); // string(3) "man"

foreach ($enum->values() as $e) {
var_dump($e); // string value
}

When i have resource for exemple Gender::man I can call Gender::man::getDesc()

The problem is that if a method in java returns Gender enum it is serialized in php as string and from string I can't make a resource

Sorry for my english, i hope you will understand me.

PS: Thanks nam for quick reply
Reply With Quote
  #5  
Old 03-29-2013, 11:27 AM
nam nam is offline
Administrator
 
Join Date: Aug 2009
Posts: 337
Default

Thanks for the clarification. I understand the problem. I'll submit a fix shortly.
Reply With Quote
  #6  
Old 03-29-2013, 11:43 AM
nam nam is offline
Administrator
 
Join Date: Aug 2009
Posts: 337
Default

Fixed for 4.0.36. See http://bugs.caucho.com/view.php?id=5411. I will commit the changes to our public svn repository in a few hours.
Reply With Quote
  #7  
Old 03-30-2013, 10:23 PM
zalmolksis zalmolksis is offline
Junior Member
 
Join Date: Mar 2013
Posts: 8
Thumbs up

It's working !
Thank you nam !
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:28 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.