?
avatar wanderlusted18
wanderlusted18
14 Nov 2018

Steps to reproduce the issue

Run the below code from a terminal

Expected result

JApplication object instatiated, traces are printed to the terminal

Actual result

Instatiation seems to fail when the parent constructor is called. T2 is never printed to the terminal

System information (as much as possible)

Joomla 3.8

Additional comments

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!

#7028

<?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";
?>
avatar wanderlusted18 wanderlusted18 - open - 14 Nov 2018
avatar joomla-cms-bot joomla-cms-bot - change - 14 Nov 2018
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 14 Nov 2018
avatar mbabker
mbabker - comment - 14 Nov 2018

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.

avatar wanderlusted18
wanderlusted18 - comment - 14 Nov 2018

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!

avatar mbabker
mbabker - comment - 14 Nov 2018

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

avatar wanderlusted18
wanderlusted18 - comment - 15 Nov 2018

Thanks again! It turned out that i was using the wrong php executable and this caused the above problems.

avatar wanderlusted18 wanderlusted18 - change - 15 Nov 2018
Status New Closed
Closed_Date 0000-00-00 00:00:00 2018-11-15 07:00:44
Closed_By wanderlusted18
avatar wanderlusted18 wanderlusted18 - close - 15 Nov 2018

Add a Comment

Login with GitHub to post a comment