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
Jason Lotito
January 21, 2013
Technology
65
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Command Line PHP Basics
Jason Lotito
January 21, 2013
More Decks by Jason Lotito
See All by Jason Lotito
tmux
jasonlotito
1
50
Getting Things Done from Someone with OCD & ADHD
jasonlotito
0
95
How We Killed Our Process, Technology Stack, and Assumptions — and Survived
jasonlotito
0
58
Twitter Bootstrap, or why being a PHP Developer is a bad idea.
jasonlotito
2
570
require.js
jasonlotito
3
100
tmux
jasonlotito
0
150
Other Decks in Technology
See All in Technology
螺旋型キャリアの生存戦略 / kinoko-conf2026
rakus_dev
1
820
OTel × Datadog で 「AI活用」を計測し、改善に繋げる
shihochan
2
580
【FinOps】データドリブンな意思決定を目指して
z63d
0
100
20260619 私の日常業務での生成 AI 活用
masaruogura
1
240
Bucharest Tech Week 2026 - Guardians of the Cloud-Native Galaxy
edeandrea
PRO
0
130
攻撃者視点で考えるDetection Engineering
cryptopeg
3
2.1k
入門!AWS Blocks
ysuzuki
1
180
GitHub Copilot app最速の発信の裏側
tomokusaba
1
240
Claude Codeをどのように キャッチアップしているか
oikon48
13
8.8k
Oracle AI Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
6
1.6k
SONiC Scale-Up Working Group から探る Scale-UpやUltraEthernet機能の実装方法
ebiken
PRO
2
470
Lightning近況報告
kozy4324
0
220
Featured
See All Featured
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
470
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
240
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
200
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.5k
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
400
How STYLIGHT went responsive
nonsquared
100
6.2k
Designing Powerful Visuals for Engaging Learning
tmiket
1
420
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