Page 1 of 1

boolean method in php

Posted: Mon Jun 22, 2009 6:39 am
by sfoley77
Hey guys I am new to working on php code and I have a method in java which I need to rewrite into php can I please get some advise on how to write the following method in php

/**
* Sets whether the customer's billing address is same as shipping address for this
* transaction.
* @param isSameAddress true is same; false otherwise
* @modelguid {CA96EFC4-E064-4716-97F4-D6E41753F457}
*/
public void setBillingAddressSameAsShipping(boolean isSameAddress)
{
isBillingAddressSameAsShipping = isSameAddress;
}
I fully understand what the method is doing its just the different syntax in php as you cant write a method with public void or add boolean isSameAddress in php.
Thanks in advance for any help provided

Best Regards
Sean

Re: boolean method in php

Posted: Mon Jun 22, 2009 6:55 am
by sfoley77
I think I figured would this code be correct:

public function setBillingAddressSameAsShipping($isSameAddress)
{
if ($isSameAddress = false){
$isBillingAddressSameAsShipping = false;
}else
$isBillingAddressSameAsShipping = true;
}

Re: boolean method in php

Posted: Mon Jun 22, 2009 7:20 am
by VladSun
sfoley77 wrote:I think I figured would this code be correct:

public function setBillingAddressSameAsShipping($isSameAddress)
{
if ($isSameAddress = false){
$isBillingAddressSameAsShipping = false;
}else
$isBillingAddressSameAsShipping = true;
}
It's absolutely incorrect ;)


= is for assigning values
== is for comparing values (no type checks)
=== is for comparing values and types

Try using :

Code: Select all

$isBillingAddressSameAsShipping = (bool)$isSameAddress;