Run the below code from a terminal
JApplication object instatiated, traces are printed to the terminal
Instatiation seems to fail when the parent constructor is called. T2 is never printed to the terminal
Joomla 3.8
Hi There,
I was trying to use the code from the below link to simply instantiate a JApplicationCli object, but it seems that my code just dies when the parent constructor is called. No error message. T1 is printed out on the terminal, but T2 is not. What am I doing wrong? Thanks!
<?php
// We are a valid entry point.
const _JEXEC = 1;
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);
// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
require_once dirname(__DIR__) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', dirname(__DIR__));
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_LIBRARIES . '/import.legacy.php';
require_once JPATH_LIBRARIES . '/cms.php';
// Load the configuration
require_once JPATH_CONFIGURATION . '/configuration.php';
// ----------------------
class TestCli extends JApplicationCli {
public function __construct() {
echo "T1\n";
parent::__construct();
echo "T2\n";
$this->config = new JConfig();
// important for storing several rows
JFactory::$application = $this;
}
public function doExecute() {
echo "T3\n";
}
}
echo "started...\n";
try {
JApplicationCli::getInstance('TestCli')->execute();
}
catch (Exception $e) {
// An exception has been caught, just echo the message.
fwrite(STDOUT, $e->getMessage() . "\n");
exit($e->getCode());
}
echo "finished...\n";
?>
Labels |
Added:
?
|
Thanks this is really helpful. Any chance you can send me an example of / link to the typical settings of these environmental variables? Many thanks!
PHP's CLI SAPI by default should define both constants that check looks for. Likewise, executing a PHP script from command line should result in $_SERVER['argv']
being populated. If this is not happening, there is a good chance that the PHP binary that you're executing is not one that is using the CLI SAPI and this would be a host/server issue that needs to be addressed
Thanks again! It turned out that i was using the wrong php executable and this caused the above problems.
Status | New | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-11-15 07:00:44 |
Closed_By | ⇒ | wanderlusted18 |
If it's dying in the constructors, odds are you are hitting this bit of code. This seems to imply your command line PHP environment is not set up as core expects.