/    Sign up×
Community /Pin to ProfileBookmark

Strict Standards: Only variables should be passed by reference

Strict Standards: Only variables should be passed by reference in /home/Dhaka/public_html/includes/functions.php on line 204

200 function getWithoutPath($filename) {
201 return end(explode(“/”,$filename));}
202

203 function getExt($name) {
204 return end(explode(‘.’, $name));
205 }
206

207 function imgExt($name) {
208 $exts[] = ‘gif’;

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 10.2016 — end()'s parameter is passed by reference, so...
[code=php]
function getExt($name)
{
$arr = explode('.', $name);
return end($arr);
}
[/code]


In this case, since the array you create is local to the getExt() function and never used again, there's (currently) no risk of a side-effect, but might as well clean it up. ?
Copy linkTweet thisAlerts:
@omprakash03authorJun 10.2016 — Thanks Sir
Copy linkTweet thisAlerts:
@ginerjmJun 10.2016 — Nogdog - I think you are mistaken in your first statement. The code posted returns "values" in all cases, nothing 'by reference'. There are no args being returned. The explode function returns a value (an array).The end function is using that value and operates upon it and returns a value without changing the incoming argument at all.
Copy linkTweet thisAlerts:
@NogDogJun 10.2016 — I believe the strict warning is for the call to end(), which is prototyped as...

mixed end ( array &$array )
[/quote]

The OP's code was passing an expression which output an array to end(), as opposed to passing an array variable.
Copy linkTweet thisAlerts:
@ginerjmJun 10.2016 — Darn little ampersand! The OP picked up on that correctly. While the call doesn't alter the array contents, it does modify the current position of the array.

OTOH - the prototype of current() may be incorrect since it indicates a pass-by-reference but states that all it does is return the current element of the array and doesn't move the pointer.
×

Success!

Help @omprakash03 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.20,
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,
)...