Quite a long time ago I wrote an external script that does this at the top:

require_once '/path/to/joomla/install/com_civicrm/civicrm.settings.php';
require_once '/path/to/joomla/install/civicrm/CRM/Core/Config.php';
$config = CRM_Core_Config::singleton( );

...so that I can use civicrm_api() calls from an external php script. Now after upgrading to the 5.x train of CiviCRM I realized my script was not working. If I manually run the script I get this error:

PHP Parse error: syntax error, unexpected '$this' (T_VARIABLE) in .../civicrm/CRM/Core/DAO.php on line 1123

In an effort to determine if this was happening in a civicrm_api() call I made a file with just the three lines quoted above and run it with php, and it produces the error. So I'm pretty confident the issue is the require_once trying to include these files, not the actual act of making an api call.

I've found numerous references to $this issues in DAO.php, but none of them are relevant to including these two files for the purposes of API calls and the line number of the failure is always different.

How can I fix this so I can use my existing script?

2 Answers 2


I think I found the issue. Command line php was 5.4.16 despite the website using 7.x.


Take a look at cv

You can write your php script without requiring anything and then run:

cv scr /path/to/script

Or use this at the start of your script:

eval(`cv php:boot`)

See cv's README for details

(For all of these you'll need to make sure the right version of php is used - preferably 7.2 at the moment.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.