How to identify incorrect use of sizeof in PHP 7.4+? - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Wednesday, April 19, 2023

How to identify incorrect use of sizeof in PHP 7.4+?

We have a project created in CodeIgniter that was started with PHP 5.6, then migrated to PHP 7.0 and now we are migrating to PHP 8.

However, our code has several places that use the sizeof function to find out if the Model functions are returning an empty value or not.

When not empty, it returns an object.

The problem is that with Visual Studio Code we cannot easily locate the functions that will present the problem, we can only identify it by running the code, even using PHP Intelephense.

Is there any way to be able to identify these possible failures via VS Code?

This is sample code that will generate an error.

//Model.php
public function exampleFunction()
{
   /**
    *
    */
   $query = $this->db->get();
   return $query->first_row();
}

//Controller.php
$result = $this->ModelM->exampleFunction();

if (sizeof($result) === 0) {
if (sizeof($result) != 0) {
if (sizeof($result) > 0) {


source https://stackoverflow.com/questions/76048009/how-to-identify-incorrect-use-of-sizeof-in-php-7-4

No comments:

Post a Comment