Sunday, November 24, 2019

php 7.3 compact() undefined variable

If you have used compact and upgraded php to 7.3 you maybe noticed warnings when variable is not defined.
PHP 7.3 made compact function strict and it will throw warnings.

Quick dirty solution:
Replace
compact
with

@compact

Normal solution:

Replace compact with array. It will take time, so if you are in production use quick dirty solution to supress notice, and when you have time make changes.
Here gist https://gist.github.com/AucT/55340f911259fd7a6e9a76b766985c6c  you can use it on any php online website and decompact your function calls.