Illegal string offset Warning PHP

0 votes

After updating my PHP version to 5.4.0-3, I have an odd PHP problem.

My array:

Array
(
    [host] => 127.0.0.1
    [port] => 11211
)

I am getting this warning when I try to access it:

 print $memcachedConfig['host'];
 print $memcachedConfig['port'];


 Warning: Illegal string offset 'host' in ....
 Warning: Illegal string offset 'port' in ...

I really don't want to just edit my php.ini and re-set the error level. Can someone please help me with this?

Jul 25, 2022 in PHP by Kithuzzz
• 38,000 points
• 3,020 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Try this:

$memcachedConfig = array("host" => "127.0.0.1","port" => "11211");
print_r($memcachedConfig['host']);

It worked for me.

answered Jul 28, 2022 by narikkadan
• 86,360 points

edited Mar 5, 2025

Related Questions In PHP

0 votes
1 answer

Error: Warning: Illegal string offset 'host' in ....

Hello @kartik,  Try this way: $memcachedConfig = array("host" => ...READ MORE

answered Aug 14, 2020 in PHP by Niroj
• 82,800 points
• 4,136 views
0 votes
1 answer

Error:“Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP

Hello @kartik, The best way for getting input string is: $value ...READ MORE

answered Apr 1, 2020 in PHP by Niroj
• 82,800 points
• 41,088 views
0 votes
1 answer

How can I handle the warning of file_get_contents() function in PHP?

Hello @kartik, This is fairly simple: if (!$data = ...READ MORE

answered Apr 7, 2020 in PHP by Niroj
• 82,800 points
• 13,421 views
0 votes
1 answer

How to resolve “must be an instance of string, string given” prior to PHP 7?

Hello, Prior to PHP 7 type hinting can only be ...READ MORE

answered Apr 20, 2020 in PHP by I Navin
• 220 points
• 6,705 views
0 votes
1 answer

How PHP Replace last occurrence of a String in a String?

Hello @kartik, You can use this function: function str_lreplace($search, ...READ MORE

answered Aug 14, 2020 in PHP by Niroj
• 82,800 points
• 4,141 views
–1 vote
1 answer
0 votes
0 answers

Showing all errors and warnings

The following script is generating a warning ...READ MORE

Jun 23, 2022 in PHP by narikkadan
• 86,360 points
• 1,391 views
0 votes
0 answers

PHP - CodeIgniter - Invalid argument supplied for foreach()

I'm attempting to use CodeIgniter to create ...READ MORE

Jul 25, 2022 in PHP by Kithuzzz
• 38,000 points
• 2,076 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
• 3,542 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
• 14,017 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP