views:

91

answers:

2

Hello,

I have this in my class

When the second function is called php errors with wrong datatype and only variables can be past by reference.

I don't know what they mean by that

This code comes from php.net If the same code is outside the class it executes fine

What am I doing wrong here, if I am working within a class?

$extensiesAllowed= array();

function __construct() {
     $this->extensiesAllowed= array("txt", "pdf");
     $this->fileName= $_FILES['file'];  
    }


    private function isAllowedExtensie($fileName) {

    return in_array(end(explode(".", $fileName)), $this->extensiesAllowed);
    }



public function check_upload() {

     if($this->fileName['error'] == UPLOAD_ERR_OK) {
      if(isAllowedExtensie($this->fileName['name'])) {
      return true;

      } 
        }
    }

the php error shows

Array
(
    [bestandsNaam] => ACCOUNT INFO.txt
    [extensiesAllowed] => 
)

Thanks, Richard

A: 

In the second function/method you should call should be calling isAllowedExtensie as $this-> isAllowedExtensie()

if($this->isAllowedExtensie($this->fileName['name'])) {

Edit: forget my second comment..

Polygraf
oh,shit I missed that one, that is one down. Now I only have the first error left. The pass by reference error.
Richard
I don't really have an idea why but pulling the statements end() and explode() apart did the trick.
Richard
Ok. I love the downvotes
Polygraf
+2  A: 

try putting the end and explode in seperate statements - I think end() may read by reference. In any case, it will help you figure out what line is causing you problems if it doesnt fix it.

Justin
`end()` does indeed pass by reference. An alternative is to use `pathinfo()` (http://php.net/pathinfo).
outis
$a=explode(".", $filename); return in_array(end($a), $this->extensiesAllowed);I cannot really understand it, but the error is gone.It doesn't seem obvious to do that, because it works fine outside the class.
Richard