Prev: Test [don't read]
Next: Battle of Spam
From: "Tanel Tammik" on 7 Jun 2010 15:40 Hi, empty() cannot check the return value of the method or function. which would be the best workaround? empty($class->method()) // gets an error i could do $method_return_value = $class->method() and then run empty() on $method_return_value or is there an better option? i would like to do it in if statement.... i wrote an class for handling file uploads and there is an method getErrors() which returns empty array in case of 0 errors and i need to check it before i move any files. i'm just curious, what is the right way to do that! Br Tanel
From: Ashley Sheridan on 7 Jun 2010 15:52 On Mon, 2010-06-07 at 22:40 +0300, Tanel Tammik wrote: > Hi, > > empty() cannot check the return value of the method or function. which would > be the best workaround? > > empty($class->method()) // gets an error > > i could do > > $method_return_value = $class->method() and then run empty() on > $method_return_value or is there an better option? i would like to do it in > if statement.... > > i wrote an class for handling file uploads and there is an method > getErrors() which returns empty array in case of 0 errors and i need to > check it before i move any files. i'm just curious, what is the right way to > do that! > > Br > Tanel > > > Are you sure this is what is giving you the error, as people are using this fine in their examples on the manual page for empty() Thanks, Ash http://www.ashleysheridan.co.uk
From: "Tanel Tammik" on 7 Jun 2010 15:56 "Ashley Sheridan" <ash(a)ashleysheridan.co.uk> wrote in message news:1275940320.2248.40.camel(a)localhost... > On Mon, 2010-06-07 at 22:40 +0300, Tanel Tammik wrote: > >> Hi, >> >> empty() cannot check the return value of the method or function. which >> would >> be the best workaround? >> >> empty($class->method()) // gets an error >> >> i could do >> >> $method_return_value = $class->method() and then run empty() on >> $method_return_value or is there an better option? i would like to do it >> in >> if statement.... >> >> i wrote an class for handling file uploads and there is an method >> getErrors() which returns empty array in case of 0 errors and i need to >> check it before i move any files. i'm just curious, what is the right way >> to >> do that! >> >> Br >> Tanel >> >> >> > > > Are you sure this is what is giving you the error, as people are using > this fine in their examples on the manual page for empty() > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > > from the php manual: Note: empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Br Tanel
From: Peter Lind on 7 Jun 2010 16:02 On 7 June 2010 21:52, Ashley Sheridan <ash(a)ashleysheridan.co.uk> wrote: > On Mon, 2010-06-07 at 22:40 +0300, Tanel Tammik wrote: > >> Hi, >> >> empty() cannot check the return value of the method or function. which would >> be the best workaround? >> >> empty($class->method()) Â // gets an error >> >> i could do >> >> $method_return_value = $class->method() and then run empty() on >> $method_return_value or is there an better option? i would like to do it in >> if statement.... >> >> i wrote an class for handling file uploads and there is an method >> getErrors() which returns empty array in case of 0 errors and i need to >> check it before i move any files. i'm just curious, what is the right way to >> do that! >> >> Br >> Tanel >> >> >> > > > Are you sure this is what is giving you the error, as people are using > this fine in their examples on the manual page for empty() > Empty only works on variables, not return values from functions. If you're checking the return value from a function, just do if ($class->method()). The return value will be cast to bool - look here for the conversions: http://dk2.php.net/manual/en/language.types.boolean.php Regards Peter -- <hype> WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 </hype>
From: "Tanel Tammik" on 7 Jun 2010 16:07 "Peter Lind" <peter.e.lind(a)gmail.com> wrote in message news:AANLkTinmvaqv-hdgJlQ_dwOQUvoJBBMBfRiXNxvqK-mG(a)mail.gmail.com... On 7 June 2010 21:52, Ashley Sheridan <ash(a)ashleysheridan.co.uk> wrote: > On Mon, 2010-06-07 at 22:40 +0300, Tanel Tammik wrote: > >> Hi, >> >> empty() cannot check the return value of the method or function. which >> would >> be the best workaround? >> >> empty($class->method()) // gets an error >> >> i could do >> >> $method_return_value = $class->method() and then run empty() on >> $method_return_value or is there an better option? i would like to do it >> in >> if statement.... >> >> i wrote an class for handling file uploads and there is an method >> getErrors() which returns empty array in case of 0 errors and i need to >> check it before i move any files. i'm just curious, what is the right way >> to >> do that! >> >> Br >> Tanel >> >> >> > > > Are you sure this is what is giving you the error, as people are using > this fine in their examples on the manual page for empty() > Empty only works on variables, not return values from functions. If you're checking the return value from a function, just do if ($class->method()). The return value will be cast to bool - look here for the conversions: http://dk2.php.net/manual/en/language.types.boolean.php Regards Peter -- <hype> WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 </hype> Thanks! It works... <?php class TestClass { protected $errors = array(); function getErrors() { return $this->errors; } } $class = new TestClass; if($class->getErrors()) { echo 'there is an value!'; } else { echo 'empty'; } ?> No need to complicate things. Br Tanel
|
Pages: 1 Prev: Test [don't read] Next: Battle of Spam |