boolean method in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sfoley77
Forum Newbie
Posts: 15
Joined: Tue Jun 02, 2009 10:13 am

boolean method in php

Post 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
sfoley77
Forum Newbie
Posts: 15
Joined: Tue Jun 02, 2009 10:13 am

Re: boolean method in php

Post by sfoley77 »

I think I figured would this code be correct:

public function setBillingAddressSameAsShipping($isSameAddress)
{
if ($isSameAddress = false){
$isBillingAddressSameAsShipping = false;
}else
$isBillingAddressSameAsShipping = true;
}
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: boolean method in php

Post 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;
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply