0

i am forced to use a wordpress theme together with my laravel framework. The wordpress theme is around 60 MB of size. Yes, it's ugly.

And no, I will not fix the entire wordpress theme only to avoid that stupid error. That would be bad as well, because if they do an update of the theme, i wouldnt be able to apply it.

Now back to the question, they do

if ($element[0]){
    ...
}else{
    return '';
}

now $element[0] can be, as expected, undefined. Now this was not a problem, unless it gets called from a laravel context, which i have to do. now the whole thing explodes with:

ErrorException in ga-scroll-event.php line 189: Undefined offset: 0

I repeat, no, i won't go and fix 60 MB of code.

what is the way to disable this error exception ?

Toskan
  • 13,911
  • 14
  • 95
  • 185

1 Answers1

0

You could just avoid the error:

if (isset($element[0]) && $element[0]){
    ...
}else{
    return '';
}
Serg Chernata
  • 12,280
  • 6
  • 32
  • 50
  • i think the OP stated he was not open to editing the template files – happymacarts Jan 04 '17 at 17:38
  • 1
    @happymacarts fair enough, that's his choice.This isn't fixing 60mb of code though. – Serg Chernata Jan 04 '17 at 17:38
  • i think that is a great solution and probably how i would do it too. – happymacarts Jan 04 '17 at 17:40
  • sure right, so i fixed it at this file, now the next file has a problem. Do i fix it as well? and the next one? these guys just coded like that. Is that my fault? and then there is a theme update, I fix all files all over again? cunning coders – Toskan Jan 04 '17 at 21:08
  • btw: you are coding like a decade ago. Shorter and nicer is `if($element[0] ?? false)` easier to read too – Toskan Jan 04 '17 at 21:10
  • @Toskan i think `if($element[0] ?? false)` works if `$element[0]` is null but here the element is not set and compiler fails to find and throws a fatal error. – Cerlin Jan 05 '17 at 07:20
  • @CerlinBoss ?? is a new php 7 language construct, you should read about it. If it is not set, it falls back to the next value. If it is set but null, it takes null and returns that – Toskan Jan 13 '17 at 00:07