I'm having to move my laravel 5.4 app to a >=PHP 7.3 Server. Upgrading the App to a higher laravel version breaks everything. So I'm stuck with making this work as is. The problem now is that Compact() method (which was used to pass variables to the view is undefined). I'm considering writing a replica of the Compact method in a helper class to make it globally available. Now I can't even replicate the PHP compact method natively. Please help with any suggestions. Whether on how to fix the issue or with a sample alternative code to the compact method.
Asked
Active
Viewed 239 times
-2
-
3the function is compact() not Compact(). Its case sensitive, hope that helps. – shahburhan Jan 31 '20 at 12:54
-
@shahburhan Function names aren't case sensitive in PHP (sadly). – Jeto Jan 31 '20 at 13:22
-
@shahburhan [PHP functions are not case sensitive](https://3v4l.org/WRmrT). – nice_dev Jan 31 '20 at 13:23
-
Can't say anything much without getting a hold of the project. Are you sure namespaces are properly defined? Does adding a \ before the function name fix it? – nice_dev Jan 31 '20 at 13:24
-
The method is not undefined, your input refers to undefined variable(s). See changelog for compact (See notes for PHP 7.3, it throws an E_NOTICE now) in the [documentation](https://www.php.net/manual/en/function.compact.php). Solution can be to just replace the compact to pass an array like `return $this->view('something', ['var' => $var, 'anotherVar' => $anotherVar]);` (or using `->with()`). On the [Laravel github](https://github.com/laravel/framework/issues/26936) it is suggested to update to 5.5 to solve it, but apparently that is not an option for you. – Francesco de Guytenaere Jan 31 '20 at 13:50
2 Answers
0
you are using an older version of laravel with new version of php.
either you can change your php version to downgrade or you can move to Laravel 5.5

Fawad Saboor
- 91
- 4
0
You should use compact()
:
$name = 'James';
surname = 'Hetfield'
return view('some-template-name', compact('name', 'surname'));

Dmitry Leiko
- 3,970
- 3
- 25
- 42