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
boolean method in php
Moderator: General Moderators
Re: boolean method in php
I think I figured would this code be correct:
public function setBillingAddressSameAsShipping($isSameAddress)
{
if ($isSameAddress = false){
$isBillingAddressSameAsShipping = false;
}else
$isBillingAddressSameAsShipping = true;
}
public function setBillingAddressSameAsShipping($isSameAddress)
{
if ($isSameAddress = false){
$isBillingAddressSameAsShipping = false;
}else
$isBillingAddressSameAsShipping = true;
}
Re: boolean method in php
It's absolutely incorrectsfoley77 wrote:I think I figured would this code be correct:
public function setBillingAddressSameAsShipping($isSameAddress)
{
if ($isSameAddress = false){
$isBillingAddressSameAsShipping = false;
}else
$isBillingAddressSameAsShipping = true;
}
= 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;There are 10 types of people in this world, those who understand binary and those who don't