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 7.3] compact() issues an E_NOTICE level error #234

Closed
drbyte opened this issue Sep 11, 2018 · 6 comments
Closed

[PHP 7.3] compact() issues an E_NOTICE level error #234

drbyte opened this issue Sep 11, 2018 · 6 comments
Assignees
Labels
bug Something isn't working fixed Bug found & fixed

Comments

@drbyte
Copy link
Contributor

drbyte commented Sep 11, 2018

  • LogViewer Version: 4.6.0
  • Laravel Version: 5.7.2
  • PHP Version: 7.3.0-beta-2
  • Hosted locally on Laravel Valet

Description:

Trying to compact a non-defined variable.

public function listLogs(Request $request)
{
$stats = $this->logViewer->statsTable();
$headers = $stats->header();
$rows = $this->paginate($stats->rows(), $request);
return $this->view('logs', compact('headers', 'rows', 'footer'));
}

Steps To Reproduce:

Followed @arcanedev-maroc instructions in #195 (comment)

composer create-project laravel/laravel fresh-laravel && cd fresh-laravel
composer require arcanedev/log-viewer
// set LOG_CHANNEL=daily
php artisan log-viewer:publish

Added logging to route:

Route::get('/', function () {
    Log::info('This is info log');

    return view('welcome');
});

screen shot 2018-09-10 at 9 11 42 pm

@drbyte
Copy link
Contributor Author

drbyte commented Sep 11, 2018

Note: same problem exists with search in

public function show($date)
{
$log = $this->getLogOrFail($date);
$levels = $this->logViewer->levelsNames();
$entries = $log->entries($level = 'all')->paginate($this->perPage);
return $this->view('show', compact('log', 'levels', 'level', 'search', 'entries'));
}

and

public function showByLevel($date, $level)
{
$log = $this->getLogOrFail($date);
if ($level === 'all')
return redirect()->route($this->showRoute, [$date]);
$levels = $this->logViewer->levelsNames();
$entries = $this->logViewer->entries($date, $level)->paginate($this->perPage);
return $this->view('show', compact('log', 'levels', 'level', 'search', 'entries'));
}

@drbyte
Copy link
Contributor Author

drbyte commented Sep 11, 2018

Note: after swapping footer with stats, and search with date, the view still contains another compact() call to query, which doesn't exist either:

{!! $entries->appends(compact('query'))->render() !!}

@arcanedev-maroc arcanedev-maroc self-assigned this Sep 11, 2018
@arcanedev-maroc
Copy link
Member

arcanedev-maroc commented Sep 11, 2018

This is why:

Note:
Before PHP 7.3, any strings that are not set will silently be skipped.

Changelog

Version Description
7.3.0 compact() now issues an E_NOTICE level error if a given string refers to an unset variable. Formerly, such strings have been silently skipped.

Source: https://secure.php.net/manual/en/function.compact.php

PHP 7.3 is not supported for the time being but it's good to know 👍

Feel free to make a PR

@arcanedev-maroc arcanedev-maroc added the bug Something isn't working label Sep 11, 2018
@arcanedev-maroc arcanedev-maroc changed the title Bug: compact(): Undefined variable: footer in LogViewerController.php:88 [PHP 7.3] compact() issues an E_NOTICE level error Sep 11, 2018
@HDVinnie
Copy link

HDVinnie commented Oct 14, 2018

Just replace usages of compact()

return $this->view('logs', compact('headers', 'rows', 'footer'));

TO

return $this->view('logs', ['headers' => $headers, 'rows' => $rows, 'footer' => $footer]);

OR

return $this->view('logs')->with('headers' => $headers, 'rows' => $rows, 'footer' => $footer);

@drbyte
Copy link
Contributor Author

drbyte commented Oct 15, 2018

@arcanedev-maroc no, this isn't a PHP 7.3 issue.

It's bugs that were created in #153 when refactoring was done which relocated some variables but didn't update the variables passed to compact, and changes were made to views.

See PR #242

@arcanedev-maroc
Copy link
Member

Patch released: v4.6.1

panique added a commit to panique/LogViewer that referenced this issue Apr 25, 2019
The current installation guide will fail for PHP 7.3, so I added this fix: It tells the user to do a composer require to version `4.6`, which will install 4.6.0. This version has an [incompatibility issue](ARCANEDEV#234) with PHP 7.3 that has been fixed in 4.6.1, so it makes sense to require that by default.

Maybe there is a better solution to require the *latest stable* of 4.6 rather than setting the .1 manually. Feel free to edit this commit :)
AppleJin512 pushed a commit to AppleJin512/LogViewer that referenced this issue Feb 21, 2023
The current installation guide will fail for PHP 7.3, so I added this fix: It tells the user to do a composer require to version `4.6`, which will install 4.6.0. This version has an [incompatibility issue](ARCANEDEV/LogViewer#234) with PHP 7.3 that has been fixed in 4.6.1, so it makes sense to require that by default.

Maybe there is a better solution to require the *latest stable* of 4.6 rather than setting the .1 manually. Feel free to edit this commit :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Bug found & fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants