CodeIgniter Forums
Problem run via the command-line [SOLVED] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Problem run via the command-line [SOLVED] (/showthread.php?tid=80047)



Problem run via the command-line [SOLVED] - hieuhiti - 09-07-2021

Hi All,
I create a simple controller for run via the command-line. But When run:
Code:
php index.php tools/messages/to

error reporting system

PHP Parse error:  syntax error in /Users/rocker/www/democommand.vn/system/Common.php on line 49

I don't interfere Common.php file. Why error?

Controller I'm refer https://codeigniter.com/user_guide/cli/cli.html#why-run-via-the-command-line

PHP Code:
namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
Tools extends Controller
{
    public function message($to 'World')
    {
        echo "Hello {$to}!" PHP_EOL;
    }



Please helpme.


RE: Problem run via the command-line - paulbalandan - 09-07-2021

Please show what code is in line 49


RE: Problem run via the command-line - hieuhiti - 09-07-2021

(09-07-2021, 09:08 AM)paulbalandan Wrote: Please show what code is in line 49



PHP Code:
if (! function_exists('app_timezone'))
{
 
/**
 * Returns the timezone the application has been set to display
 * dates in. This might be different than the timezone set
 * at the server level, as you often want to stores dates in UTC
 * and convert them on the fly for the user.
 *
 * @return string
 */ 
 
function app_timezone(): string
 
{
 
$config config(App::class);

 return 
$config->appTimezone;
 }



Line 49 is:  function app_timezone(): string

If I delete this function, the same PHP Parse error appear next function has syntax "function {any_name} : string".

I think Terminal don't accept syntax "function {any_name} : string". But This is Ci4 System file, I don't interfere


RE: Problem run via the command-line - paulbalandan - 09-07-2021

What PHP version is your terminal using?

Run `php -v`


RE: Problem run via the command-line - hieuhiti - 09-08-2021

@paulbalandan, with your suggestion.
After Check Php Version,
I found different between "php -v" and php_info(), I fixed it.
My Problem has been fixed.
Thanks you very much!

For "Problem run via the command-line", We Check Php Version by syntax: "php-v" on terminal. Required php 7.2 or higher


RE: Problem run via the command-line - InsiteFX - 09-08-2021

Please edit your post and in the title on top add to the end [SOLVED]

Thank you.