Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Command Line PHP Basics
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Jason Lotito
January 21, 2013
Technology
64
1
Share
Command Line PHP Basics
Jason Lotito
January 21, 2013
More Decks by Jason Lotito
See All by Jason Lotito
tmux
jasonlotito
1
48
Getting Things Done from Someone with OCD & ADHD
jasonlotito
0
94
How We Killed Our Process, Technology Stack, and Assumptions — and Survived
jasonlotito
0
54
Twitter Bootstrap, or why being a PHP Developer is a bad idea.
jasonlotito
2
560
require.js
jasonlotito
3
99
tmux
jasonlotito
0
150
Other Decks in Technology
See All in Technology
freeeで運用しているAIQAについて
qatonchan
1
610
データモデリング通り #5オンライン勉強会: AIに『ビジネスの文脈』を教え込むデータモデリング
datayokocho
0
280
大学職員のための生成AI最前線 :最前線を、AIガバナンスとして読み直すためのTips
gmoriki
2
4.2k
20260515 ID管理は会社を守る大切な砦!〜🔰情シス向け〜
oidfj
0
510
セキュリティ対策、何からはじめる? CloudNative環境の脅威モデリングと リスク評価実践入門 #cloudnativekaigi
varu3
5
910
会社説明資料|株式会社ギークプラス ソフトウェア事業部
geekplus_tech
0
240
Purview 勉強会報告 Microsoft Purview 入門しようとしてみた
masakichixo
1
410
生成AI時代に信頼性をどう保ち続けるか - Policy as Code の実践
akitok_
1
390
カオナビに Suspenseを導入するまで / The Road to Suspense at kaonavi
kaonavi
1
450
iOS・Androidの文字サイズ設定をWebViewに!モバイルUIのアクセシビリティTips
shincarpediem
2
110
Claude Code で使える DuckDB Skills を試してみた / DuckDB Skills and Claude Code
masahirokawahara
1
150
可視化から活用へ — Mesh化・Segmentation・アライメントの研究動向
gpuunite_official
0
200
Featured
See All Featured
It's Worth the Effort
3n
188
29k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
690
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
190
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
210
Documentation Writing (for coders)
carmenintech
77
5.3k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Producing Creativity
orderedlist
PRO
348
40k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
350
Transcript
#!/usr/bin/php PHP on the command line Tuesday, February 19, 13
./phpcl --overview • Basic PHP Commands • PHP Scripts •
Arguments • Real World Example Tuesday, February 19, 13
Practical PHP On the command line Tuesday, February 19, 13
php -v → php -v PHP 5.3.15 with Suhosin-Patch (cli)
(built: Aug 24 2012 17:45:44) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies Tuesday, February 19, 13
php --ini → php --ini Configuration File (php.ini) Path: /etc
Loaded Configuration File: /private/etc/php.ini Scan for additional .ini files in: (none) Additional .ini files parsed: (none) Tuesday, February 19, 13
php lint Tuesday, February 19, 13
php -l → php -l stdin.php No syntax errors detected
in stdin.php Tuesday, February 19, 13
php -l → php -l stdin.php PHP Parse error: parse
error in stdin.php on line 5 Errors parsing stdin.php Tuesday, February 19, 13
php -l • Automate during rollup, commits • Prevent silly
mistakes, because, let’s face it, you aren’t doing TDD • Sometimes tools might modify output, even accidentally • Ensures code can run on the version of PHP installed Tuesday, February 19, 13
php -a PHP’s interactive shell Not quite a REPL, doesn’t
really matter (Read-Evaluate-Print Loop) Tuesday, February 19, 13
php -a → php -a Interactive shell php > $a
= range(1,3); php > var_dump($a); array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) } Tuesday, February 19, 13
php -a php > class Foo { public $bar =
'baz'; } php > $foo = new Foo(); php > echo $foo->bar; baz Tuesday, February 19, 13
php -a php > function p($v){ php { echo md5('this_is_really_secure_right?'.$v);
php { } php > p(134); bb33942de0b7f8f7fda76ef41ee55654 php > p('happy'); fbc327fa6e16a971130d72bd72e7e55f Tuesday, February 19, 13
php -a php > var_dump(array()===array()); bool(true) php > var_dump( ((array)
new stdClass()) === array() ); bool(true) php > class Foo{function __toString(){return '';}} php > $foo = new Foo(); php > var_dump( ((string) $foo) === '' ); bool(true) Tuesday, February 19, 13
php -a • Great for resolving quick question • Winning
arguments • Temporary scripts, functions Tuesday, February 19, 13
php -a • Has autocomplete php > new PDO PDO
pdo_drivers PDOException PDORow PDOStatement Tuesday, February 19, 13
PHP Scripts Tuesday, February 19, 13
Running Scripts • Command Line • $ php ./script.php •
Bash Bang • #!/usr/bin/php Tuesday, February 19, 13
Command Line • Useful for executing code that might also
run from a web server • Doesn’t assume existing installation directory Tuesday, February 19, 13
Bash Bang • $ ./script.php • $ ./script • $
script • #!/usr/bin/env php > #!/usr/bin/php Tuesday, February 19, 13
getopt <?php $options = getopt("f:hp:"); var_dump($options); → php ./getopt.php -f
hello -p asdf -h array(3) { ["f"]=> string(5) "hello" ["p"]=> string(4) "asdf" ["h"]=> bool(false) } Tuesday, February 19, 13
getopt • f: - Required value • v:: - Optional
value • a - No value • $opts = getopt(‘f:v::a’); Tuesday, February 19, 13
getopt • getopt( $shortOptions, $longOptions ) Tuesday, February 19, 13
getopt long options • $longOptions = array( • ‘required:’, •
‘optional::’, • ‘option’ • ); • $ script --required 123 --optional=”value is here” --option Tuesday, February 19, 13
getopt • $opts = getopt(‘v’,array(‘verbose’)); • $ script -v •
$ script --verbose Tuesday, February 19, 13
getopt • php.net/getopt • > 5.3 Works on windows, plus
support for ::, =, and longopts • < 5.3 misses those critical features Tuesday, February 19, 13
time to see code Tuesday, February 19, 13