www.webdeveloper.com
Results 1 to 7 of 7

Thread: Strict Standards: Only variables should be passed by reference in

  1. #1
    Join Date
    Apr 2012
    Posts
    15

    Strict Standards: Only variables should be passed by reference in

    It is strange error (first time I've evern seen this kind of notice)
    so i've looked over internet and i've found nothing so far...
    here is the code that is causing it:
    Code:
    function mkthumb($src, $Twidth) {
          $name = basename(strtolower($src));
          $F = end(explode(".", $name));
          if($F == "jpg" OR $F == "jpeg") {
             $img = imagecreatefromjpeg($src);
          }
          else if($F == "png") {
             $img = imagecreatefrompng($src);
          } else {
                            $img = imagecreatefromgif($src);
                    }
    at the line $F = end (explode....
    seems to be the problem
    So any suggestions?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    See the manual page for end(), and notice in the description section that the array argument is passed by reference (indicated by the "&"). In your code you are passing the result of explode(), which while it is an array (assuming it succeeds), there is no variable to pass as a reference. Therefore, you need an intermediate step to create an array variable (and ideally should verify it is, in fact, a successful assignment before assuming it's okay):
    PHP Code:
          $name basename(strtolower($src));
          
    $exploded explode("."$name);
          if(
    $exploded === false) { throw new Exception("Oops!"); } // or whatever you want to do
          
    $F end(exploded)); 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    PS: Personally, I'd probably use getimagesize() to figure out what type of image it is.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Apr 2012
    Posts
    15
    Well i toke your advice,and your code , but now it's not "Strik Standards" it's Fatal error with same infonly variables should be passed at....
    it's at the same line
    Code:
    $F = end(exploded));
    :S

    actually it worked ,just had to add the $ symbol and remove one )
    ty , problem solved!
    Last edited by wdas; 09-20-2012 at 01:33 AM.

  5. #5
    Join Date
    Mar 2009
    Posts
    452
    using strtolower is a good idea while checking for file extensions in case if extension is JPG or jPg etc...

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,178
    Quote Originally Posted by ZABI View Post
    using strtolower is a good idea while checking for file extensions in case if extension is JPG or jPg etc...
    Another reason I like getimagesize(), as it looks at the actual file contents, not whatever name a user happened to assign to it.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Mar 2009
    Posts
    452
    yea, this way we can also check for minimum or maximum image size limit.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles