Answers.Body: <p>I think I found the issue. Command line php was 5.4.16 despite the website using 7.x.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-14T01:21:22.123Z
Answers.LastActivityDate: 2019-08-14T01:21:22.123Z
Answers.UserDisplayName: jbourne
Answers.Body: <p>Take a look at <a href="https://github.com/civicrm/cv" rel="nofollow noreferrer">cv</a></p>
  
  <p>You can write your php script without requiring anything and then run:</p>
  
  <pre><code>cv scr /path/to/script
  </code></pre>
  
  <p>Or use this at the start of your script:</p>
  
  <pre><code>eval(`cv php:boot`)
  </code></pre>
  
  <p>See cv's README for details</p>
  
  <p>(For all of these you'll need to make sure the right version of php is used - preferably 7.2 at the moment.)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-14T09:03:54.963Z
Answers.LastActivityDate: 2019-08-14T09:03:54.963Z
Answers.UserDisplayName: Aidan
Body: <p>Quite a long time ago I wrote an external script that does this at the top:</p>
  
  <pre><code>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( );
  </code></pre>
  
  <p>...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:</p>
  
  <blockquote>
    <p>PHP Parse error:  syntax error, unexpected '$this' (T_VARIABLE) in .../civicrm/CRM/Core/DAO.php on line 1123</p>
  </blockquote>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>How can I fix this so I can use my existing script? </p>
  
Tags: <api><civicrm.settings.php>
Title: How do i properly include civicrm.settings.php to use api calls?
ThreadText: # How do i properly include civicrm.settings.php to use api calls?
  
  (Asked by: username_0 on 2019-08-14)
  
  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?
  
  **Tags:** api, civicrm.settings.php
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2019-08-14. Score: 2
  
  I think I found the issue. Command line php was 5.4.16 despite the website using 7.x.
  
  
  ---
  
  ### Answer by username_1 on 2019-08-14. Score: 1
  
  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.)
  
  
  ---
  
  