Skip to content

PHP Fatal error: Uncaught Exception: E_NOTICE in PHP 7.4 #649

@zigomir

Description

@zigomir

It seems like PHP 7.4 is more strict when accessing an empty array. In 7.3 you'd simply get NULL, but now it also throws an exception.

Problem is caused by this https://github.com/leafo/lessphp/blob/master/lessc.inc.php#L663-L665 part of code.

Simple reproduction is possible with

<?php

$args = [];
$last = end($args);
$last[0];

If you execute above code with PHP 7.3.12, nothing happens, while 7.4.0 throws and prints the error.

You can reproduce it here: http://sandbox.onlinephpfunctions.com/

Now, because we're using lessphp in production and we're migration to PHP 7.4 I simply made this change

- if ($last[0] == "rest") {
+ if ($last && $last[0] == "rest") {

which solves our specific issue. Not sure if this really is correct change though.

Do you run tests on php 7.4 too? Would you be interested in getting a PR which reproduces and fixes this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions