Last active
April 27, 2017 03:08
-
-
Save zackad/0670fed334825d7e278329fa478b8c70 to your computer and use it in GitHub Desktop.
Example calling php command with python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example of using python to call external command | |
# In this case a php command to run php script | |
from subprocess import call | |
# First argument is command, second & third argument is parameters | |
call(["php", "./index.php", "Hello Dunia"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Hello; | |
/** | |
* Hello World Class | |
*/ | |
class HelloWorld | |
{ | |
private $message; | |
public function __construct() | |
{ | |
$this->message = 'Hello World!' . PHP_EOL; | |
} | |
public function getMessage() | |
{ | |
return $this->message; | |
} | |
public function setMessage($str) | |
{ | |
if (empty($str)) { | |
return; | |
} | |
$this->message = $str . PHP_EOL; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'HelloWorld.php'; | |
$hello = new Hello\HelloWorld; | |
// Print initial message | |
echo $hello->getMessage(); | |
// Set and print new message | |
if (!empty($argv[1])) { | |
// if there is message from command line argument | |
$hello->setMessage($argv[1]); | |
} else { | |
$hello->setMessage('Hello again there!'); | |
} | |
echo $hello->getMessage(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment