2

I came across a fat-free framework where indexes are accessed without checking if there's data present or not.

few e.g.

e.g.1 
$sObj = new Site($db); // this returns null?
$site = $sObj->getById($sessionSiteId)[0];

e.g.2
$ppObject = new Page($db);
$pheader = $ppObject->getByCodeandsiteid($siteid,'Header');        
F3::set('headercode',$pheader[0]['description']);

so these are just few cases. Most of the practice done is to just access the index. This throws error in my env. php 8.1 and fat-free 3.8.1.

But running this same code on my colleague's env. : php 5.6.40 and fat-free 3.5.1` this doesn't throw error but simply gives null value.

I also checked with some random unassigned variable on his env. and to my surprise, this also seem to simply give null instead of error.

Is this expected behavior on previous versions?

Also checked in phpinfo() that error_reporting value for both is 22527.

Azima
  • 3,835
  • 15
  • 49
  • 95
  • 5
    Undefined indexes didn't throw errors in PHP 5.6. They just threw a notice. They still don't throw errors though (PHP 8.2), they throw warnings (which at least is slightly higher than a notice). Check the error reporting level. For some lazy reasons, it is (or at least was back when that version was still relevant and supported) quite common that people didn't log notices. – M. Eriksson Jan 03 '23 at 03:06
  • 3
    This entirely depends on environment configuration, specifically around `error_reporting` – Phil Jan 03 '23 at 03:06
  • @Phil @M.Eriksson checked `error_reporting` value for both, it is the same - `22527`. Could it be that the later versions of php didn't treat `undefined indexes` as warning and rather as errors? – Azima Jan 03 '23 at 05:04
  • You can see here how each version handles array access on null ~ https://3v4l.org/kcOfs – Phil Jan 03 '23 at 22:20

0 Answers0