-1

I have test.php like below:

<?
    class Track{

        public function displaySong($title, $duration){

            $data = $title + $duration

            return $data;
        }

    }
?>

how to run it on CMD?... like if i do like this with cmd

song1 = Track("Britney - Toxic", "0:3:51")
song2->displaySong()

It returns

Song :  Britney - Toxic, Duration:  0:3:51

on cmd display

7
  • Are you asking how to execute a PHP file via CMD? Commented Jun 11, 2018 at 3:07
  • 3
    Possible duplicate of Running PHP script from the command line Commented Jun 11, 2018 at 3:07
  • nope, ham asking how to make my script work. its error (' Commented Jun 11, 2018 at 3:11
  • Well, could provide the error? The expected output? Commented Jun 11, 2018 at 3:11
  • when I execute song1 = Track("Britney - Toxic", "0:3:51") its return syntax error near unexpected token ('` Commented Jun 11, 2018 at 3:14

1 Answer 1

0
  1. you should use "",this is a suggestion php.net give enter image description here (this is been blocked by stackoverflow)

    1. you have an error at this : "$data = $title + $duration" => "$data = $title + $duration;"

    2. if you want run a php file in CMD, you need use as : php test.php argv1 argv[2] ... , argv is the data you want to give the test.php

    3. and the last , your test.php should add some code:

        public function displaySong($title, $duration){
      
           $data = $title + $duration;
      
           echo $data;
        }
      

      } $song = new Track(); $song->displaySong($argv1, $argv[2]);

Sign up to request clarification or add additional context in comments.

1 Comment

I run this php file and I get a result ➜ ~ php c.php 1 2 3

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.