• Resolved fireproofsocks

    (@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

    (@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.

    Thread Starter fireproofsocks

    (@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

    (@scribu)

    I rewrote the code to eliminate the @ operator:

    https://plugins.trac.www.ads-software.com/changeset/298338/scb-framework

    and updated the development version of Custom Field Taxonomies:

    https://plugins.trac.www.ads-software.com/changeset/298340/custom-field-taxonomies

    Thread Starter fireproofsocks

    (@fireproofsocks)

    Nice! Thanks!

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