|
From: <php...@li...> - 2008-09-02 19:21:04
|
By the way. When I call the validation method from a command line java
program, it works perfectly.
Charles Shaffer
Senior Analyst
NTN-Bower Corporation
php...@li...
Sent by: php...@li...
09/02/2008 02:16 PM
Please respond to php-java-bridge-users
To: php...@li...
cc:
Subject: [Php-java-bridge-users] Return Boolean from Java to PHP
How do you return a boolean value from a java routine to a php module?
I have a java method that validates an account number and returns true or
false. The Java declaration is
public Boolean isValidAccountNumber(String acctnum) {
in the method I return true; or return false;
In the php code I check it like this
if ($IDEAS->isValidAccountNumber($acctnum) == false) {
No matter what I do, it always acts as if the return value was true. Even
when I force the Java method to always return false;
Is this a type issue?
Charles Shaffer
Senior Analyst
NTN-Bower Corporation
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
Build the coolest Linux based applications with Moblin SDK & win great
prizes
Grand prize is a trip for two to an Open Source event anywhere in the
world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
php-java-bridge-users mailing list
php...@li...
https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
--
This email was Anti Virus checked by Astaro Security Gateway. http://www.astaro.com
|
|
From: <php...@li...> - 2008-09-03 14:06:10
|
>>Try:
>>$res = (bool) $IDEAS->isValidAccountNumber($acctnum) ;
>>if ($res === false) {
I tried
$result = (bool)$IDEAS->isValidAccountNumber($acctnum);
echo "result = $result";
And got
result = 1
This can't be correct because I set up the isValidAccountNumber function
to always return false.
I tried
$result = $IDEAS->isValidAccountNumber($acctnum);
echo "result = $result";
And got
result = [[o:Boolean]:"false"]
At least false is in there somewhere. I guess the question I should be
asking is how do I extract the value from the Boolean object returned by
Java?
When I try
$resval = $result->value;
echo "resval = $resval";
It takes a dump
Error [[o:Exception]:"java.lang.Exception: GetProperty failed:
[[o:Boolean]]->value.
Cause: java.lang.NoSuchFieldException: value (with args:).
If not value, then what?
Charles Shaffer
Senior Analyst
NTN-Bower Corporation
|
|
From: <php...@li...> - 2008-09-03 14:12:22
|
Just try:
// Notice the !
if(!$res){
...
}
On Wed, Sep 3, 2008 at 9:05 AM, <php...@li...
> wrote:
> >>Try:
>
> >>$res = (bool) $IDEAS->isValidAccountNumber($acctnum) ;
> >>if ($res === false) {
>
> I tried
> $result = (bool)$IDEAS->isValidAccountNumber($acctnum);
> echo "result = $result";
>
> And got
> result = 1
>
> This can't be correct because I set up the isValidAccountNumber function
> to always return false.
>
> I tried
> $result = $IDEAS->isValidAccountNumber($acctnum);
> echo "result = $result";
>
> And got
> result = [[o:Boolean]:"false"]
>
> At least false is in there somewhere. I guess the question I should be
> asking is how do I extract the value from the Boolean object returned by
> Java?
>
> When I try
> $resval = $result->value;
> echo "resval = $resval";
>
> It takes a dump
> Error [[o:Exception]:"java.lang.Exception: GetProperty failed:
> [[o:Boolean]]->value.
> Cause: java.lang.NoSuchFieldException: value (with args:).
>
> If not value, then what?
>
> Charles Shaffer
> Senior Analyst
> NTN-Bower Corporation
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> php-java-bridge-users mailing list
> php...@li...
> https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
>
--
Roger José Padilla Camacho
|
|
From: <php...@li...> - 2008-09-03 14:17:19
|
I had a similar problem and I use java_values() to solve, try :
if( java_values($IDEAS->isValidAccountNumber($acctnum)) ){
...
}
Hope this Help,
Benjamin.
php...@li... a écrit :
>>> Try:
>>>
>
>
>>> $res = (bool) $IDEAS->isValidAccountNumber($acctnum) ;
>>> if ($res === false) {
>>>
>
> I tried
> $result = (bool)$IDEAS->isValidAccountNumber($acctnum);
> echo "result = $result";
>
> And got
> result = 1
>
> This can't be correct because I set up the isValidAccountNumber function
> to always return false.
>
> I tried
> $result = $IDEAS->isValidAccountNumber($acctnum);
> echo "result = $result";
>
> And got
> result = [[o:Boolean]:"false"]
>
> At least false is in there somewhere. I guess the question I should be
> asking is how do I extract the value from the Boolean object returned by
> Java?
>
> When I try
> $resval = $result->value;
> echo "resval = $resval";
>
> It takes a dump
> Error [[o:Exception]:"java.lang.Exception: GetProperty failed:
> [[o:Boolean]]->value.
> Cause: java.lang.NoSuchFieldException: value (with args:).
>
> If not value, then what?
>
> Charles Shaffer
> Senior Analyst
> NTN-Bower Corporation
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> php-java-bridge-users mailing list
> php...@li...
> https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
>
|
|
From: <php...@li...> - 2008-09-03 14:37:10
|
>>Just try:
>>// Notice the !
>>if(!$res){
>> ...
>>}
Same thing.
Charles Shaffer
Senior Analyst
NTN-Bower Corporation
|
|
From: <php...@li...> - 2008-09-03 14:39:54
|
That's so strange... in PHP the number 1 is like true, that also not works
for you?
On Wed, Sep 3, 2008 at 9:37 AM, <php...@li...
> wrote:
> >>Just try:
>
> >>// Notice the !
> >>if(!$res){
> >> ...
> >>}
>
> Same thing.
>
> Charles Shaffer
> Senior Analyst
> NTN-Bower Corporation
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> php-java-bridge-users mailing list
> php...@li...
> https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
>
--
Roger José Padilla Camacho
|
|
From: <php...@li...> - 2008-09-03 14:51:07
|
>>That's so strange... in PHP the number 1 is like true, that also not works >>for you? I believe the problem is that after the call, $res contains a Java Boolean object, not the boolean value of 0 or 1. I am trying the java_values approach now. Charles Shaffer Senior Analyst NTN-Bower Corporation |
|
From: <php...@li...> - 2008-09-03 14:57:01
|
Benjamin wrote:
>>I had a similar problem and I use java_values() to solve, try :
>>if( java_values($IDEAS->isValidAccountNumber($acctnum)) ){
That was it. Thanks so much Benjamin.
Charles Shaffer
Senior Analyst
NTN-Bower Corporation
|
|
From: <php...@li...> - 2008-09-03 15:34:34
|
Of course, the error is in the method declaration, see:
*public Boolean isValidAccountNumber(String acctnum) { *
Java is performing an automatic typecasting from native boolean to object
java.lang.Boolean.
You must change your method declaration by (notice the native boolean):
*public boolean isValidAccountNumber(String acctnum) {*
Please test this change and give your feedback.
Greetings from Cartagena / Colombia
--
Roger Padilla
On Wed, Sep 3, 2008 at 9:57 AM, <php...@li...
> wrote:
> Benjamin wrote:
> >>I had a similar problem and I use java_values() to solve, try :
>
> >>if( java_values($IDEAS->isValidAccountNumber($acctnum)) ){
>
> That was it. Thanks so much Benjamin.
>
> Charles Shaffer
> Senior Analyst
> NTN-Bower Corporation
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> php-java-bridge-users mailing list
> php...@li...
> https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
>
--
Roger José Padilla Camacho
|
|
From: <php...@li...> - 2008-09-04 09:37:32
|
Hi,
> Of course, the error is in the method declaration
Not really.
> *public Boolean isValidAccountNumber(String acctnum) { *
> *public boolean isValidAccountNumber(String acctnum) {*
from the PHP/Java Bridge's point of view both are equivalent, unless you define
define ("JAVA_PREFER_VALUES", 1);
before including java/Java.inc. The JAVA_PREFER_VALUES forces a round-trip for each primitive return value.
Regards,
Jost Boekemeier
__________________________________________________
Do You Yahoo!?
Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails.
http://mail.yahoo.com
|
|
From: <php...@li...> - 2008-09-03 16:04:11
|
Roger says:
>>You must change your method declaration by (notice the native boolean):
>>*public boolean isValidAccountNumber(String acctnum) {*
Thank you. I will try this when I get a chance and let you know. Since
it is working, I have moved to another assignment, but when I get time I
will try this. I appreciate the information. I wasn't aware of the
difference between boolean and Boolean.
Charles Shaffer
Senior Analyst
NTN-Bower Corporation
|
|
From: <php...@li...> - 2008-09-02 20:05:33
|
Try:
$res = (bool) $IDEAS->isValidAccountNumber($acctnum) ;
if ($res === false) {
On Tue, Sep 2, 2008 at 2:20 PM, <php...@li...
> wrote:
> By the way. When I call the validation method from a command line java
> program, it works perfectly.
>
> Charles Shaffer
> Senior Analyst
> NTN-Bower Corporation
>
>
>
>
> php...@li...
> Sent by: php...@li...
> 09/02/2008 02:16 PM
> Please respond to php-java-bridge-users
>
>
> To: php...@li...
> cc:
> Subject: [Php-java-bridge-users] Return Boolean from Java to
> PHP
>
>
> How do you return a boolean value from a java routine to a php module?
>
> I have a java method that validates an account number and returns true or
> false. The Java declaration is
>
> public Boolean isValidAccountNumber(String acctnum) {
>
> in the method I return true; or return false;
>
> In the php code I check it like this
>
> if ($IDEAS->isValidAccountNumber($acctnum) == false) {
>
> No matter what I do, it always acts as if the return value was true. Even
>
> when I force the Java method to always return false;
>
> Is this a type issue?
>
> Charles Shaffer
> Senior Analyst
> NTN-Bower Corporation
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the
> world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> php-java-bridge-users mailing list
> php...@li...
> https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
>
> --
> This email was Anti Virus checked by Astaro Security Gateway.
> http://www.astaro.com
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> php-java-bridge-users mailing list
> php...@li...
> https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
>
--
Roger José Padilla Camacho
|
|
From: <php...@li...> - 2008-09-03 19:51:38
|
Hi,
> Try:
> $res = (bool) $IDEAS->isValidAccountNumber($acctnum) ;
No! PHP automatically casts a primitive value into a boolean, if it is part of the boolean expression. However, you cannot convert a PHP object into PHP value using a type cast. The only exception is the (string) type cast, which internally calls $res->__toString()[1].
Therefore the PHP/Java Bridge library contains two special procedures, one to fetch a PHP value from a Java object, the other one to cast a Java object into a PHP primitive type. Please see our documentation for details.
Regards,
Jost Boekemeier
[1] PHP's behaviour is insane, of course. In order to convert the following PHP object into a value one needs two type casts:
class Clazz_ONE {
function __toString() { return "1"; }
}
$one = new Clazz_ONE();
var_dump( (int) $one)
=> ERROR
var_dump( (int)(string) $one)
=> 1
__________________________________________________
Do You Yahoo!?
Sie sind Spam leid? Yahoo! Mail verfügt über einen herausragenden Schutz gegen Massenmails.
http://mail.yahoo.com
|