[wp-trac] [WordPress Trac] #39195: Undefined index: extension in class-wp-image-editor-imagick.php on line 152
WordPress Trac
noreply at wordpress.org
Fri Dec 9 02:01:15 UTC 2016
#39195: Undefined index: extension in class-wp-image-editor-imagick.php on line 152
--------------------------+-----------------------------
Reporter: JaworskiMatt | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 4.7
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
This is a follow-up to #37608.
The '''EXACT SAME ERROR was just introduced with WordPress 4.7''' in
class-wp-image-editor-imagick.php line 152 and is now generating notices
all over my development instance when uploading images via a plugin I'm
developing
{{{#!php
try {
$this->image = new Imagick();
$file_parts = pathinfo( $this->file );
$filename = $this->file;
if ( 'pdf' == strtolower( $file_parts['extension'] ) ) {
$filename = $this->pdf_setup();
}
}}}
The $info variable is created using PHP's very own pathinfo() like this:
{{{
$info = pathinfo( $this->file );
$dir = $info['dirname'];
$ext = $info['extension'];
}}}
According to PHP documentation, the extension index can be missing (not
set) if the file does not have one.
http://php.net/manual/en/function.pathinfo.php
The code above will obviously generate a notice in such a scenario. An
easy way around this is NOT to assume the "extension" index is present,
for example like this:
{{{
$dir = pathinfo( $this->file, PATHINFO_DIRNAME );
$ext = pathinfo( $this->file, PATHINFO_EXTENSION );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39195>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list