• Skip to main content

Victor Font Consulting Group, LLC

Digital Business Strategists

Call Us:

+1 919-604-5828

  • Home
  • Care Plans
    • Care Articles
    • Optional Subscriptions
  • Consultations
  • Products
    • Code Snippets
    • Public GitHub Repositories
    • Gist Snippets
    • Pastebin Snippets (Free)
    • Free Plugins
  • FAQs
  • Support
    • Graphic Design
  • Our Team
    • Contact
    • Speakers
    • Portfolio
  • Resources
    • Free WordPress Video Training
    • Tutorials
    • Articles
    • Cybersecurity
    • EU Referral Network
You are here: Home / Code Snippet / Fix PHP Illegal String Offset Error

Fix PHP Illegal String Offset Error

By Victor M. Font Jr.
November 24, 20141 Comment

PHP
Image Courtesy of http://efffective.com
After upgrading PHP to Version 5.4 or higher, it's not uncommon for some WordPress plugins to produce the “PHP Warning: Illegal string offset" error message. The reason for this is because in Versions 5.4 and above, the default error reporting level has changed.

PHP 5 introduced a new error level: E_STRICT. In PHP versions prior to 5.4.0, you would have to explicitly enable the E_STRICT reporting level, which was disabled by default. With the release of PHP 5.4.0, E_STRICT is included in E_ALL. According to the PHP documentation:

STRICT messages provide suggestions that can help ensure the best interoperability and forward compatibility of your code. These messages may include things such as calling non-static methods statically, defining properties in a compatible class definition while defined in a used trait, and prior to PHP 5.3 some deprecated features would issue E_STRICT errors such as assigning objects by reference upon instantiation.

After I upgraded my WordPress installation to PHP 5.4, my error_log started filling up with the Illegal string offset warning for a couple of lines in the Genesis Simple Sidebars plugin. I am a devout advocate of the Genesis Framework. The plugin is written by Nathan Rice a key contributor to the Genesis framework, so I was a little surprised by the errors.

The code that produces the warning is found in the plugin's source at lines 104 through 109. Specifically, the errors are produced by lines 2 and 4 in the code below.

genesis_register_sidebar( array(
	'name'        => esc_html( $info['name'] ),
	'id'          => $id,
	'description' => esc_html( $info['description'] ),
	'editable'    => 1,
) );

Syntactically, there's absolutely nothing wrong with the code The warning message displays because one of the array values is empty. There are several ways to fix this.

  1. You could turn off error messages altogether, but then you wouldn't know if you had a real problem.
  2. You could edit the plugin's code to test for empty arrays, but this is not recommended at all. If a plugin update comes through, your changes will be overwritten and you'll be back to square one.
  3. You can do as I did and fix the data.

Genesis Simple Sidebars Fix

The following fix applies only to the Genesis Simple Sidebars plugin. For any other plugin, I suggest you look for an empty array value as your code processes the loop.

First, access your database through PHPMyAdmin or MySQLWorkbench. then execute the following SQL statement. (make sure you change "my database" to the name of your database.

SELECT * FROM mydatabase.wp_options where option_name = 'ss-settings';

Next, delete:

i:0;s:20:"__return_empty_array";

from the beginning of serialized string and subtract 1 from the first integer after a:.

In my case the before looked like:

a:7:{i:0;s:20:"__return_empty_array";s:16:"about-me-sidebar";

and the after looks like:

a:6:{s:16:"about-me-sidebar";

This fix works like a charm for Genesis Simple Sidebars. I only hope it helps provide insight into a direction you can pursue to track down your own Illegal string offset warnings.

Formidable Honeypot Fix

Another plugin that exhibits the Illegal string offset warning is Formidable HoneyPot. Formidable HoneyPot is an anti-spam add-on for the popular Formidable Forms plugin. The "honeypot" technique for SPAM protection is invisible to humans and tricks spambots into filling out an invisible form field. When the form is validated, if that invisible field has been populated, the form is not submitted.

As with the Genesis Simple Sidebars plugin, the warning error in Formidable HoneyPot is being produced because the developer is trying to evaluate an empty array. Actually, he's evaluating a non-existent array. Line 86 of the code, which produces the error, evaluates whether or not the form is a multi-page form. The array in question only exists in a multi-page form. So if you only have single page forms, as most people do, the code produces and error.

The developer's original code is:

//don't require if not on the last page
global $frm_next_page, $frm_vars;
if((is_array($frm_vars) and isset($frm_vars['next_page']) and isset($frm_vars['next_page'][$values['form_id']])) or (is_array($frm_next_page) and isset($frm_next_page[$values['form_id']])))
	return $errors;

To fix the error, I simply wrapped the developer's code in a new if statement.

//don't require if not on the last page
global $frm_next_page, $frm_vars;
if(!is_array($frm_vars) or !is_array($frm_next_page)) {
	// do nothing
} else {
	if((is_array($frm_vars) and isset($frm_vars['next_page']) and isset($frm_vars['next_page'][$values['form_id']])) or (is_array($frm_next_page) and isset($frm_next_page[$values['form_id']])))
		return $errors;
}

Just to be clear, this is not the way I like to fix things. I hate changing another developer's source code, especially when the chance is good that it will be overwritten in the future. The only reason I did it this time is because it appears that the developer has been unresponsive to the posts in the plugins forums. One user posted about this error 4 months ago and there has been no response. I guess I'm going to have to write a tutorial on how to add honeypot fields to Formidable Pro without using a plugin.

  • 15shares
  • Facebook0
  • Twitter1
  • Pinterest0
  • LinkedIn2
  • Print
  • SMS12

About Victor M. Font Jr.

Victor M. Font Jr. is an award winning author, entrepreneur, and Senior IT Executive. A Founding Board Member of the North Carolina Executive Roundtable, he has served on the Board of Advisors, of the North Carolina Technology Association, the International Institute of Business Analysis, Association of Information Technology Professionals, Toastmasters International, and the North Carolina Commission for Mental Health, Developmental Disabilities, and Substance Abuse Services. He is author of several books including The Ultimate Guide to the SDLC and Winning With WordPress Basics, and Cybersecurity.

Reader Interactions

VictorFont.com runs on the Genesis Framework

Genesis FrameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Check out the incredible features and the selection of designs. It's that simple—start using Genesis now!

Click here to download The Genesis Guide for Absolute Beginners (PDF - 1.4 MB)

Leave a Reply Cancel reply

Your email address and website will not be published. Required fields are marked *
Posting a comment means that you agree with and accept our Comment & Product Review Policy

Comments

  1. Brad

    June 18, 2016 at 4:14 am

    Great read! I remember Genesis and haven’t touched it much in a while. Glad I came across this looking for solutions to a similar issue. You just saved me lots of time in trying to repair/clean a hacked site.

    Reply

Call: +1 919-604-5828

Send us an E-mail

Accessibility Statement | Affiliate Marketing Disclosure | Capability Statement

Cookie Policy | Comment & Product Review Policy | Privacy Policy | Site Map | Terms & Conditions

Copyright © 2003–2021 Victor M. Font Jr.

Return to top of page
Cover image: 5 Things You Can Fix On Your Website In The Next Week To Increase Engagement

Attract New Customers Automatically for Free!

  • Learn how to use the Internet to attract REAL clients
  • Avoid the 3 big mistakes EVERYBODY makes
  • Put this system on AUTOPILOT with the tools the Pros use!

GET YOUR COPY!

This little ebook has helped hundreds of business professionals get real results.
Now it's your turn!

ebook lead capture
Privacy Policy
{"cookieName":"wBounce","isAggressive":false,"isSitewide":true,"hesitation":"","openAnimation":false,"exitAnimation":false,"timer":"","sensitivity":"","cookieExpire":"7","cookieDomain":"","autoFire":"","isAnalyticsEnabled":false}
We only use analytical cookies on our website that allow us to recognize and count the number of visitors, but they do not identify you individually. They help us to improve the way our website works. By clicking Accept you, agree to cookies being used in accordance with our Cookie Policy.OkNoCookie policy