Re: Unexcepted $this
| From: | Philip Thompson | Date: | Mon, 10 Mar 2008 15:25:29 +0000 |
| Subject: | Re: Unexcepted $this | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-271205@lists.php.net to get a copy of this message | ||
On Mar 10, 2008, at 8:32 AM, Ray Hauge wrote:
Murat BEŞER wrote:Good call.I can't under stood but PHP gaves me an error: "UnExcepted $this" for " || $this->getFileExtension($file) == 'jpg' " When I removed jpg extension check it's okay... PHP script runs well. What is the problem :) public function loadImages($folder) {getFileExtension($file) == 'png' || $this->getFileExtension($file)$result = $this->filemanager->fecthFiles($folder); $images = array(); if (sizeof($result)>=1 && $result !== false) { foreach ($result as $file) { if ($this->getFileExtension($file) == 'gif' || $this-== 'jpg') { $images[] = array('name'=>$file); } } } return $images; }Try storing the value in a variable first. It'll also have the side-effect of being marginally faster too.
$extension = $this->getFileExtension($file); if ($extension == 'gif' || $extension || 'png' || $extension == 'jpg') {Correction: ... $extension == 'png' ... Personally, I like the in_array() version better - it cleaner and you can expand upon it more more easily. $extensions = array('gif, 'png', 'jpg' [, 'm4a'[, 'etc']]); if (in_array($extension, $extensions)) { ... }
// do something } That might help, but I would think that the way you had it would also work. Let us know what happens when you use the variable like I showed above. Thanks, --Ray HaugeHTH, ~Philip "Personally, most of my web applications do not have to factor 13.7 billion years of space drift in to the calculations, so PHP's rand function has been great for me..." ~S. Johnson