/    Sign up×
Community /Pin to ProfileBookmark

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);
}
[/code]

at the line $F = end (explode….
seems to be the problem
So any suggestions?

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 19.2012 — See the manual page for [url=http://php.net/end]end[/url](), 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):
[code=php]
$name = basename(strtolower($src));
$exploded = explode(".", $name);
if($exploded === false) { throw new Exception("Oops!"); } // or whatever you want to do
$F = end(exploded));
[/code]
Copy linkTweet thisAlerts:
@NogDogSep 19.2012 — PS: Personally, I'd probably use getimagesize() to figure out what type of image it is.
Copy linkTweet thisAlerts:
@wdasauthorSep 20.2012 — Well i toke your advice,and your code , but now it's not "Strik Standards" it's Fatal error with same info:only variables should be passed at....

it's at the same line
$F = end(exploded));
:S

actually it worked ,just had to add the $ symbol and remove one )

ty , problem solved!
Copy linkTweet thisAlerts:
@ZABISep 20.2012 — using strtolower is a good idea while checking for file extensions in case if extension is JPG or jPg etc...
Copy linkTweet thisAlerts:
@NogDogSep 20.2012 — using strtolower is a good idea while checking for file extensions in case if extension is JPG or jPg etc...[/QUOTE]

Another reason I like getimagesize(), as it looks at the actual file contents, not whatever name a user happened to assign to it. ?
Copy linkTweet thisAlerts:
@ZABISep 22.2012 — yea, this way we can also check for minimum or maximum image size limit.
×

Success!

Help @wdas spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...