PHP: Only variables should be passed by reference – PHP Error

- Advertisement -

Most of the PHP developers get this error A PHP Error was encountered

[html]

- Advertisement -

A PHP Error was encountered
Severity: Notice
Message: Only variables should be passed by reference
Filename: filename.php
Line Number: 104
Backtrace:

- Advertisement -

[/html]

This is due to one of the reasons that you need to pass a real variable and not a function that returns an array. It is because only the actual variable may be passed by reference.

Example:

[php]

$file_name = "image01.jpg";
echo end(explode(‘.’, $file_name));

[/php]

This renders the above notice. From the PHP Manual for end​ function, we can read this:

The array. This array is passed by reference because it is modified by the function. This means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference.

Here, we expect to print text, which is the last exploded element. It does print but with this notice. To fix this, one needs to split into two lines:

Only variables should be passed by reference. PHP Error

Note:

The problem is, that end requires a reference because it modifies the internal representation of the array (i.e. it makes the current element pointer point to the last element) PHP Error

The result of explode(‘.’, $file_name) cannot be turned into a reference. This is a restriction in the PHP language, that probably exists for simplicity reasons.

[php]

$file_name = "image01.jpg";
$fileStrings = explode(‘.’, $file_name);
echo end($fileStrings);

[/php]

 

- Advertisement -

Share it with friends:

Related Articles

How to create best Bootstrap FAQ template? [Full Source Code]

Bootstrap FAQ Bootsrap Frequently Asked Questions. bootstrap faq, bootstrap faq template, bootstrap 4 faq template, bootstrap 3 faq template, bootstrap compost faq, faq in...

Old Instagram Logo with HTML and CSS quality logo

Create the Old Instagram Logo by HTML and CSS. Old Instagram Logo CSS  for new style Instagram logo  logo.html <div class="Instagram"> <span class="Instagram-strip"></span> <span class="Instagram-viewfinder"></span> ...

Chrome plans to start blocking resource-heavy ads in August Update

Chrome plans to start blocking resource-heavy ads that drain a lot of battery in August, Google announced today on its Chromium blog (via VentureBeat). Chrome...

How to create Sitemaps on Blogger for Google and Bing

Create Sitemaps on Blogger The XML Sitemap file is like a directory of all web pages that exist on your website or blog. Google,...

How to speed up WordPress with Plesk and WP Super Cache, WP Rocket, Autoptimize Free

https://websavers.ca/how-to-speed-up-wordpress   This guide includes 9 tips to show you how to take just about any WordPress site to a maximum 1-2 seconds load time. If you’ve...

What is “8203​” HTML character? Why is being injected into my HTML?

This “8203;” HTML character is intended for line break control; it has no width, but its presence between two characters does not prevent increased...

Get in Touch

166FansLike
114FollowersFollow

Latest Posts

How to create best Bootstrap FAQ template? [Full Source Code]

Bootstrap FAQ Bootsrap Frequently Asked Questions. bootstrap faq, bootstrap faq template, bootstrap 4 faq template, bootstrap 3 faq template, bootstrap compost faq, faq in...

Old Instagram Logo with HTML and CSS quality logo

Create the Old Instagram Logo by HTML and CSS. Old Instagram Logo CSS  for new style Instagram logo  logo.html <div class="Instagram"> <span class="Instagram-strip"></span> <span class="Instagram-viewfinder"></span> ...

Chrome plans to start blocking resource-heavy ads in August Update

Chrome plans to start blocking resource-heavy ads that drain a lot of battery in August, Google announced today on its Chromium blog (via VentureBeat). Chrome...

How to create Sitemaps on Blogger for Google and Bing

Create Sitemaps on Blogger The XML Sitemap file is like a directory of all web pages that exist on your website or blog. Google,...

How to speed up WordPress with Plesk and WP Super Cache, WP Rocket, Autoptimize Free

https://websavers.ca/how-to-speed-up-wordpress   This guide includes 9 tips to show you how to take just about any WordPress site to a maximum 1-2 seconds load time. If you’ve...

Popular Posts

This is the proposed SpaceX internet plan. WOW

Sometime in 2019, SpaceX will be launching the first of its proposed 4000 satellites to provide ultra-high speed internet to the entire world. This is...

Failed to execute ‘postMessage’ on ‘DOMWindow’: https://www.accounts.google.com !== http://yourdoamin.com

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://accounts.google.com') does not match the recipient window's origin ('https://www.yourdomain.com') What is the problem actually? How to...

Instagram Logo CSS gradient with HTML best 2 quality logo

The new Instagram logo create by CSS gradient. Read more about Gradient here Instagram logo CSS and HTML Method - 1 logo.html &lt;link rel="stylesheet" href="//maxcdn.bootstrapcdn. com/font-awesome/4.3.0/css/font-awesome.min.css"&gt; &lt;span class="instagram"&gt; ...

DB import failure at CREATE ALGORITHM = UNDEFINED DEFINER Error: #1227 – Access denied – Fixed

CREATE ALGORITHM=UNDEFINED DEFINER=root@`%` SQL SECURITY INVOKER VIEW...  When import the SQL file from localhost to remote server, if the server is shared or not given...

Huawei P30 Pro vs Samsung Galaxy S10 plus camera – Amazing performance

We've got the brand new Huawei P30 Pro versus the Samsung Galaxy S10 plus. I want to find out which is best photos videos...