Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notice: Undefined index - Solving with isset?

Tags:

php

magento

Notice: Undefined index: extension  in /var/www/.. on line 187

    //185 - $f_name = $this->filename;
    //186 - $path_parts = pathinfo($f_name);
    //187 - $file_ext = $path_parts['extension'];

After some googleing I've seen alot of Isset being used. But I'm in doubt, about how to use it, in this case? Is it even going to solve the problem?

like image 559
Thomas Nielsen Avatar asked Dec 02 '22 21:12

Thomas Nielsen


1 Answers

Yes, you can use isset in this case. You first check if the key is set before trying to access it. I would use the ternary operator to set a default value if you need to.

$file_ext = isset($path_parts['extension']) ? $path_parts['extension'] : null;
like image 160
tigrang Avatar answered Dec 23 '22 21:12

tigrang