Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zigomir opened this issue Mar 18, 2020 · 3 comments
Closed

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

zigomir opened this issue Mar 18, 2020 · 3 comments

Comments

@zigomir
Copy link

zigomir commented Mar 18, 2020

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?

@Bonscho
Copy link

Bonscho commented May 29, 2020

Same here. Also could provide help on fixing this. Please let me know whether this is appreciated.

@Bonscho
Copy link

Bonscho commented May 29, 2020

As the PHP docs state the return value of end() is false for an empty array. So the following should fix this issue in less.inc.php from line 663.

// check for a rest
$last = end($args);
if (is_array($last) && $last[0] == "rest") {
	$rest = array_slice($orderedValues, count($args) - 1);
	$this->set($last[1], $this->reduce(array("list", " ", $rest)));
}

@srmmedia
Copy link

srmmedia commented Jan 6, 2021

As the PHP docs state the return value of end() is false for an empty array. So the following should fix this issue in less.inc.php from line 663.

// check for a rest
$last = end($args);
if (is_array($last) && $last[0] == "rest") {
	$rest = array_slice($orderedValues, count($args) - 1);
	$this->set($last[1], $this->reduce(array("list", " ", $rest)));
}

Thank You . I have the error from LionThemes helper using a wordpress plugin but mine is on line 665. I have been pulling my hair out for the last week trying to figure this out. I have scoured the internet up and down all ways around and this comment and code you gave fixed it. My god why is this information so hard to find?

@zigomir zigomir closed this as completed Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants