-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
bugVerified issues on the current code behavior or pull requests that will fix themVerified issues on the current code behavior or pull requests that will fix them
Description
PHP Version
8.4
CodeIgniter4 Version
4.6.3
CodeIgniter4 Installation Method
Composer (using codeigniter4/appstarter)
Which operating systems have you tested for this bug?
Linux
Which server did you use?
apache
Database
No response
What happened?
When rendering a view cell whose class name does not contain _cell, CodeIgniter 4 throws a TypeError due to an invalid argument passed to substr().
Steps to Reproduce
Create a View Cell class that does not include _cell in its class name.
Example:
class ProductCard extends \CodeIgniter\View\Cells\Cell
{
public function render()
{
return view('product_card');
}
}Call it in a view:
<?= view_cell('App\Cells\ProductCard') ?>The application throws the TypeError.
Expected Output
CodeIgniter should gracefully handle cases where _cell is not found in $viewName and avoid passing false as a substring length to substr().
Anything else?
After upgrading to PHP 8.4, this line in Cell.php causes a TypeError:
$possibleView1 = $directory . substr($viewName, 0, strrpos($viewName, '_cell')) . '.php';To prevent the error, it currently has to be written as:
$possibleView1 = $directory . substr($viewName, 0, intval(strrpos($viewName, '_cell'))) . '.php';Using intval() ensures that false is safely converted to 0, avoiding the type mismatch introduced in PHP 8.4.
Metadata
Metadata
Assignees
Labels
bugVerified issues on the current code behavior or pull requests that will fix themVerified issues on the current code behavior or pull requests that will fix them