WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: Custom Field Taxonomies] Fix PHP Notices!

[Resolved] [Plugin: Custom Field Taxonomies] Fix PHP Notices!

  • fireproofsocks
    Member

    @fireproofsocks

    You gotta fix PHP notices in this plugin before it can be considered functional. You MUST turn on PHP notices when developing a plugin, otherwise you have no way of knowing if your plugin is using clean code.

    Here’s the fist Notice:
    Notice: Uninitialized string offset: 0 in /path/to/wordpress3/html/wp-content/plugins/custom-field-taxonomies/scb/Forms.php on line 216

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author scribu
    Member

    @scribu

    You gotta fix PHP notices in this plugin before it can be considered functional.

    It’s perfectly functional, even with the notices.

    That said, I salute your campaign to rid plugins of PHP notices!

    Please post steps to reproduce.

    Also, it would be nice if you could paste the actual line that produces the notice. The reason I’m asking is because I suspect your PHP environment is ignoring the @ operator.

    fireproofsocks
    Member

    @fireproofsocks

    I disagree strongly: if your notices are printing into form fields (as one example), those values get submitted into the plugin and you will not get the behavior you expected, and the plugin is thus broken. Granted, your plugin isn’t doing this, but the bottom line is that notices are not acceptable in a plugin meant for mainstream use.

    To reproduce:

    1. Turn on PHP notices
    2. install the plugin on a fresh install of WordPress 3.0.1
    3. Click tools menu.

    Produces this notice:
    Notice: Uninitialized string offset: 0 in /path/to/wordpress3/html/wp-content/plugins/custom-field-taxonomies/scb/Forms.php on line 216

    This is the line:
    $match = @self::$formdata[str_replace( '[]', '', $$i1 )];

    It throws a notice because $formdata is not initialized. I would suggest using something like this in that particular block:

    if (!empty(self::$formdata))
    {
    	$key = str_replace( '[]', '', $$i1 );
    	$match = self::$formdata[$key];
    	if ( is_array( $match ) ) {
    		$match = $match[$i];
    	}
    }

    Also, don’t use the “@” to suppress errors unless you absolutely need to. PHP has certain cases that you simply CAN’T anticipate — e.g. you can’t test whether or not a file is valid PHP before you include it, so that’s a legitimate place to use error-supprssing or a try/catch block.

    This is some good code — it’s well-documented and pretty easy to follow and it’s a nice contribution to the WP repo. I was going nuts last night after downloading over 20 different plugins and nearly all of them were developed without notices enabled, so forgive me if my comment came across as over-zealous.

    Plugin Author scribu
    Member

    @scribu

    I rewrote the code to eliminate the @ operator:

    http://plugins.trac.wordpress.org/changeset/298338/scb-framework

    and updated the development version of Custom Field Taxonomies:

    http://plugins.trac.wordpress.org/changeset/298340/custom-field-taxonomies

    fireproofsocks
    Member

    @fireproofsocks

    Nice! Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] [Plugin: Custom Field Taxonomies] Fix PHP Notices!’ is closed to new replies.