Jump to content

PHP Undefined Constant Error in Catalina

Recommended Posts

Every since I've upgraded to Catalina I have a workflow that is throwing an error but I cannot figure out why. It is a script folder that searches file in a folder. Here is the error:


[08:11:59.413] Logging Started...
[08:12:03.783] Recent Downloads[Script Filter] Queuing argument ''
[08:12:04.065] Recent Downloads[Script Filter] Script with argv '(null)' finished
[08:12:04.069] Recent Downloads[Script Filter] Warning: Use of undefined constant BASE_DIR - assumed 'BASE_DIR' (this will throw an Error in a future version of PHP) in Command line code on line 1

Warning: Use of undefined constant FILE_PATTERN - assumed 'FILE_PATTERN' (this will throw an Error in a future version of PHP) in Command line code on line 8


Here is the code for the script filter:


define(BASE_DIR, getenv('HOME') . '/Downloads');
$file_pattern = "{query}";
if ( $file_pattern ) {
	$file_pattern = trim($file_pattern);
	$file_pattern = preg_quote($file_pattern);
	$file_pattern = '/' . str_replace(' ', '.', $file_pattern) . '/i';
define(FILE_PATTERN, $file_pattern);
$dir_contents = scandir(BASE_DIR);
$files = array();
foreach ( $dir_contents as $file ) {
	$files[$file] = filemtime(BASE_DIR . '/' . $file);
arsort($files, SORT_NUMERIC);
//filter out non matching files
if ( $file_pattern ) {
	foreach ( $files as $file => $modtime ) {
		if ( ! preg_match(FILE_PATTERN, $file) ) {
$items = new SimpleXMLElement("<items></items>");
if ( count($files) == 0 ) {
	$c = $items->addChild('item');
	$c->addAttribute('arg', 'No Match');
	$c->addAttribute('valid', 'no');
	$c->arg = 'No Match';
	$c->addAttribute('type', 'file');
	$c->title = 'No Match';
	$c->subtitle = '';
	$c->icon = 'icon.png';
	$c->icon->addAttribute('type', 'default');
foreach( $files as $basename => $modtime ) {
	$fullpath = BASE_DIR . '/' . $basename;
	if ( substr($basename, 0, 1) != '.' ) {
		$c = $items->addChild( 'item' );
		$c->addAttribute('arg', $fullpath);
		$c->arg = $fullpath;
		$c->addAttribute('type', 'file');
		$c->title = $basename;
		$c->subtitle = $fullpath;
		$c->icon = $fullpath;
		$c->icon->addAttribute('type', 'fileicon');
echo $items->asXML();


I can't quite figure out what went wrong? I've used this for a long time however if there is an easier way to do this I'm also open for ideas.

Link to comment
Just now, alfredclough said:

I wonder why it worked for years


Because PHP was a very stupid language that is trying to be less stupid while not breaking things too much. Constant names and array keys without quotes have been deprecated for many years. I guess Catalina includes a newer version of PHP that finally makes that a real error (or it's configured to make it an error).


Link to comment
  • 8 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...