Re: (Need help) Beginner's question
| From: | Stuart Dallas | Date: | Thu, 31 Jul 2014 08:07:02 +0000 |
| Subject: | Re: (Need help) Beginner's question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323699@lists.php.net to get a copy of this message | ||
On Thursday, July 31, 2014, Sachin Raut <imsachinraut@gmail.com> wrote:
> Hi
>
> I have a question in this following code.
> <?php
>
> class A
>
> {
>
> public $country;
>
> function __construct($data=array())
>
> {
>
> if(!isset($data))
>
> {
>
> trigger_error("Couldn't construct address with a ".get_class());
>
> }
>
> }
>
> }
>
> $obj=new A();
>
> ?>
>
> I am not sending any "array" as an argument while creating an object. And
> hence "if statement" in constructor should have been executed, but it
> displays blank page. My query is why it's not executing "if statement"?
>
You are giving it a default value of an empty array, therefore the variable
is set. Either change the default to null or change the !isset($data) to
simply !$data.
--
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/