まえがき
私は不機嫌です。 私は多くのことについて文句を言います。 私はテクノロジーの世界ではあまり好きではなく、これは予測可能です。プログラミングは騒々しい若い規律であり、私たちの誰もそれが何をしているのか少しも考えていません。
スタージョンの法則を考えると、私たちは人生を理解するのに十分なものを持っています。
ここに別の問題があります。 PHPは単に使用するのに不便なだけでなく、私には不向きで、最適ではないか、私の宗教的信念に対応していません。 私が避けようとしている言語についての多くの良いことと、私が好きな言語についての多くの悪いことを話すことができます。 さあ、聞いて! 興味深い議論になります。
PHPは1つの例外です。 実際、PHPのすべての詳細は多少壊れています。 言語、構造、生態系:すべてが
悪い 。 そして、1つの殺人的なものを指摘することさえできません、そのような欠陥は体系的です。 PHPの欠陥を体系化しようとするたびに、私は徹底的に検索に迷い込み、ますますひどい小さなことを発見します(フラクタル)。
PHPは障害であり、私の技術の毒です。 私はそれがいかに壊れているか、そして他に何も学びたくないすべての承認された恋人をどれほど称賛するかについて夢中になります。 彼はポジティブな資質を無視できるほどの正当性を持っており、彼が存在することさえ忘れたい。
類推
欲求不満を説明するためにメルにそれをぼんやりさせたところ、彼女は私がここでそれを再現することを主張しました:
PHPの何が問題なのかさえ言えません。 ツールボックスを想像してください。 ツールキット。 見た目は良く、ツールはツールのようなものです。
あなたはドライバーを取り、3枚の花びらが付いた十字を見る。 さて、あなたにとってはあまり役に立ちませんが、いつか必要になるかもしれません。
ハンマーを取り、それが両側で分岐していることを恐れています。 もちろん、それはまだ適切です、つまり、ストライカーの中央に釘を打ち、反対にハンドルを握ることができます。
ノッチのないプライヤーを取ります。 彼らは平らで滑らかです。 それほど便利ではありませんが、ボルトを外すことはできます。
などなど。 すべての楽器は奇妙でねじれていますが、完全に役に立たないほどではありません。 また、セット全体に特定の問題はありません。 すべてのツールがあります。
今、何百万人もの大工がそのようなツールのセットを使用して、次のように言っていると想像してください。 私は他に何も使ったことがないので、うまく機能します!」 そして、大工は、五角形の部屋と屋根を逆さまにした彼らが建てた家を見せてくれます。 あなたはドアをノックします、それはちょうど中に落ちて、彼らは彼らのドアを壊したためにあなたに怒鳴ります。
PHPの問題点は次のとおりです。
力の整列
私は、言語が有用で生産的であるために次の品質を持たなければならないと主張し、PHPはそれらを簡単に壊します。 それらが重要であることに同意しない場合、正直に言って、私たちが何かについて合意に達する方法を想像することはできません。
- 言語は予測可能でなければなりません。 言語は、人間のアイデアを表現し、それをコンピューターで実行するための媒体であるため、プログラムの正確さを人間が理解することは重要です。
- 言語は完全でなければなりません。 類似するものは類似しているべきであり、異なるものは異なるべきです。 言語の一部の知識は、残りの言語の学習と理解に役立つはずです。
- 言語は短くするべきです。 古い言語に固有のステレオタイプを減らすために、新しい言語が存在します。 (すべて機械語でプログラムできます。)同時に、言語は独自のパターンの導入を避けるべきです。
- 言語は信頼できるものでなければなりません。 言語-問題を解決するためのツール。 それら自体が表す問題は最小限でなければなりません。 理解できない瞬間は恥ずかしさを引き起こします。
- 言語をデバッグする必要があります 。 何かがうまくいかない場合、プログラマーはそれを修正しなければなりません、そして私たちが得ることができるすべての助けが必要です。
私の立場はこれです:
- PHP :
mysql_real_escape_string, E_ACTUALLY_ALL - PHP :
strpos, str_rot13 - PHP : «C API»-,
=== - PHP :
==, foreach ($foo as &$bar) - PHP : , error reporting.
, , . , , , .
PHP. , . :(
- , « », « - ». . , - ? , , .
- , . , , . , . PHP , , . .
- , « C API». , C ? C! , CGI-.
- : « , ». , - - . , C: , « ».
- , Facebook Wikipedia PHP. ! Brainfuck', . , , , - ; .
- ! ; PHP, , - , , :)
: Python. , , . ,
; , , .
PHP-, PHP. , - , PHP. .
PHP
CPAN « Perl». Perl, , .
PHP-
.
PHP,
PHP . .
, : PHP — . , , , , (, ,
!). , -
, , . , PHP: .
, .
- . , null .
global . , , — PHP . .- . , PHP , ; , Perl, , Python.
- «» . PHP — , … , , . ( ), . , .
- , . "SPL-", :
$x = new SplBool(true); $x = "foo"; . -, . - ( ). notice, .
- ; . (, Perl-
use constant.) - . . , camelCase .
array() — . array , $func = "array"; $func(); .list($a, $b) = .... list() — array. .(int) , C, ; int. : var_dump(int) , parse error, .(integer) — (int). (bool)/(boolean) (float)/(double)/(real).(array) (object) . , : (array) , , . , , - , . ( .)include() C- #include: . , PHP-.- . .
include() ( ), . $foo[] = $bar.echo — , .empty($var) , , empty($var || $var2) parse error'. - empty?- :
if (...): ... endif; .
- PHP
@( DOS) . - PHP . , . ( fatal error' — . .)
- Parse error' PHP , , - .
- PHP
:: T_PAAMAYIM_NEKUDOTAYIM, << T_SL. «», , , :: << . - , .
E_STRICT , , , .E_ALL — E_STRICT.- , , . ,
E_STRICT , :
- ,
$foo->x.(warning) - , , .( )
- .(notice)
- -, .(notice)
- , .(notice)
2 < "foo" ( )foreach (2 as $foo); (warning)
:
- ,
$foo::x. (fatal error) - , . (parse error)
- . (fatal error)
- . (parse error)
list . (parse error)- ,
foo()[0]. (parse error, 5.4, . )
parse error'. __toString . PHP… , . ( fatal error, .)- PHP- PHP- . , , .
- PHP- (
trigger_error) try/catch. - ,
set_error_handler. - ,
set_exception_handler , try mod_php. - Fatal error' (
new ClassDoesntExist()) . fatal error', . Shutdown- , ( ), .
finally, wrapper-( , , ; , , ) . , Java, , finally « PHP». ?
- .
- , , .
- , , , , , .
- «type hint'», .
int string object , , int PHP .( (int) . ) - mixed, number callback.
- , :
function foo(string $s) {}
foo("hello world");
:
PHP Catchable fatal error: Argument 1 passed to foo() must be an instance of string, string given, called in...
- , «type hint'» .
string. ReflectionParameter::getClass(), type hint , , . - Type hint .
- (dispatch, )
call_user_func_array(' ', func_get_args()). func_get_args fatal error , , func_get_args . ? ( PHP 5.3.) - . ? . (, , , , .)
- «» . , , . .
&. - .. , private-, . ( 5.4? .)
- . , « ».
- , , , . ( ?)
- ( , ). null.
func_num_args, func_get_arg func_get_args. .
- PHP C, Java. , . , camelCase
getFoo Java-. , ? Perl, Python Ruby: - «» ; PHP __get . Java, , - PHP, . - . , .
- ( Perl) .
instanceof , , . Java? first-class ?
is_a. , .get_class ; typeof. is_subclass_of.- ,
instanceof (, int ). is_int . - ; . … parse error'.
clone — ?!- - Java Perl.
$obj->foo, $obj::foo. .- (
Class::method). (. ) $this. new, private, public, protected, static . Java-? , , — C++ .- private-. private-, , . , , -.
- , «list»,
list() — ( ) . , (. monkeypatching).($foo->list() .) - (
new Foo(bar()) bar() ), , .( PHP 5.3.) __autoload fatal error.- .
__construct — , __init__ Python. , . - .
__construct, parent::__construct() fatal error'. - , (
for...as), ( ) . , ArrayIterator. , slice' - , «first class»-. - , , .
- , ; . . ( ) ,
__toString. echo . - (. ordering).
- ; .
Perl «some assembly required»(
. « »), Python — « », PHP — «,
C ».
- . PHP, php.ini, : ( ) .
- namespace', . .
- :
- :
strpos/str_rot13, php_uname/phpversion, base64_encode/urlencode, gettype/get_class - «to» 2:
ascii2ebcdic, bin2hex, deg2rad, strtolower, strtotime - + +:
base64_decode, str_shuffle, var_dump versus create_function, recode_string - :
array_filter($input, $callback) array_map($callback, $input), strpos($haystack, $needle) array_search($needle, $haystack) - :
usleep microtime i ,array_. .
- . :
- ImageMagick, GraphicsMagick( ImageMagick), EXIF-( ImageMagick).
- bbcode', .
- XML-.
DOM(-), DOM XML( -), libxml, SimpleXML, «XML Parser», XMLReader/XMLWriter , . - , . - : SPPLUS MCVE. ?
- MySQL:
mysql, mysqli PDO.
C
, . PHP — -, - . C API, :
- «» , , PHP .
- (. ), PHP .
mysql_real_escape_string, , mysql_escape_string, MySQL C API.- ( MySQL). MySQL .
- , .
dba_nextkey dba_firstkey segfault'. ctype_*( ctype_alnum) C- , , , isupper.
. , PHP .
? Perl,
sort {$b <=> $a}. Python
.sort(reverse=True). PHP,
rsort().
- C-:
curl_error, json_last_error, openssl_error_string, imap_errors, mysql_error, xml_get_error_code, bzerror, date_get_last_errors . - :
array_multisort, arsort, ksort, krsort, natsort, natcasesort, sort, rsort, uasort, uksort, usort - :
ereg, eregi, mb_ereg, mb_eregi, preg_match, strstr, strchr, stristr, strrchr, srcpos, stripos, strrpos, strripos, mb_strpos, mb_strrpos , . - :
strstr/strchr, is_int/is_integer/is_long, is_float/is_double, pos/current, sizeof/count, chop/rtrim, implode/join, die/exit, trigger_error/user_error... scandir . , ( ), . . , .str_split . chunk_split .- . , API, bzip2, LZF, phar, rar, zip gzip/zlib.
- .. (
call_user_func_array), printf/vprintf sprintf/vsprintf. , .
preg_replace /e(eval) , eval' .strtok C-, . , PHP ( C ), , strtok(3)( ) PHP .parse_str GET-, . register_globals , . (, , .)explode . ; PHP , str_split « ».- ,
strftime, C API . date . - "
gzgetss — gz- HTML-." . mbstring
- «-», .
- . « ». , .
ereg_*, . preg_* , UTF-8, - PCRE.
reflection
- .
compact extract — . - PHP, .
classkit , runkit classkit ; Reflection*- ; . , , ? get_class($obj) . get_class() , . , : get_class(null)… , get_class(). . !stream_* . «tell» . ( .)register_tick_function . unregister_tick_function ; , , .php_uname OC. , PHP , ; . .fork exec . pcntl, . popen pid.session_decode , . $_SESSION, , .
curl_multi_exec curl_errno , curl_error.mktime : , , , , , .
.
, , awk Prolog C. , .
- — 32- 32- . PHP, . . GMP BC. ( 64- . .)
- PHP
0, 012 . , 08 . 8( 9) . 01c . pi — . , M_PI.- ,
pow.
- . ASCII, .
mbstring, . - , UTF-8- .
- ASCII. ,
é É. - ,
"$foo['key']" — . ( ) ${...}/{$...}. "${foo[0]}" . "${foo[0][0]}" — . , $ . Perl( )?
.
- , , , . ? ?(. ) ? .
=> — . , array(...) foreach.- , ..
-1 0. - , , ;
array(...) — . (PHP 5.4 «», [...].) => Perl, foo => 1 ( Perl; .) PHP ; PHP — , .- , , .
array_diff, « ».
$first = array("foo" => 123, "bar" => 456);
$second = array("foo" => 456, "bar" => 123);
echo var_dump(array_diff($first, $second));
? array_diff , ; . , ; .
array_diff , ; . array_rand , .- , PHP- :
array("foo", "bar") != array("bar", "foo")
array("foo" => 1, "bar" => 2) == array("bar" => 2, "foo" => 1)
, . ( .) array_fill , false.- (...) . ; , .
array_reverse .- , .
- «Quickhash», - « - » . , . , , «Quickhash».
ArrayObject( ) . . , , , ArrayObject' .
- — . - , . ;
var_dump(strstr) , , "strstr". «» . create_function eval. ( — !). , . NUL-, ( PHP- , NUL).__lambda_func, create_function — eval __lambda_func, . __lambda_func , fatal error.
- (
++) NULL' 1. (--) NULL' NULL. . - .
Web-
- ,
php.ini PHP , . PHP- , , php.ini. - PHP CGI. PHP- . Python- .
«PHP-», , PHP . Zend, , PHP, -. - PHP- — , . , , mysql-, .
- PHP « » PHP .
, , PHP( ), mod_rewrite, FastCGI, Server:. <?php ... ?>, , ( «headers already sent»). — ?>; PHP .
PHP; . , , Python, Ruby Perl. PHP .
, Web- - . : Web- , Web-, , Web-, , Web-, . Web- .
- PHP Apache. Web- ( ) .
php.ini PHP-, . php.ini ; shared- , , ; ini_set, Apache .htaccess. . , , .- «» PHP- . , PHP? Apache.
- « » routing , , URL', . «partial'» C, . (
.svn) . mod_php ; , , URL . - CGI, , .
- , Apache PHP, . , PHP
SetHandler .php- PHP, AddHandler , Google AddHandler. .
AddHandler, Apache, « php» — .php-. ! Apache , . , , index.html.en, HTML- . Apache .
, , . , PHP-, , .php. , foo.php.txt; , Apache PHP, .
, « » « »; , Web-, , — PHP « ». CGI +x, -, PHP . ; .
Web-. PHP, , «Web-», - .
- . PHP, , , .
- XSS-. , «
htmlspecialchars» — XSS-. XSS-. - CSRF-. .
- API . , PDO, API .
- routing'. . , ,
mod_rewrite ( .htaccess) . - .
- .
- .
- ; « ».
PHP , . .
"<script>" SQL, HTML.
« ».
; , «». : placeholder' SQL, .
- PHP «»(. sanitizing): .
addslashes, stripslashes - — , .- , . . , ;
pcntl_fork pcntl_exec. escapeshellcmd escapeshellarg . , Windows, escapeshellarg (.. Bourne shell), escapeshellcmd , Windows cmd ( , ).- MySQL-, , prepared statement'.
PHP- SQL- ,
sprintf is_numeric,
mysql_real_escape_string,
addslashes ( « »!). PDO , .
PHP . , … .
register_globals. , PHP 5.4. . .include HTTP URL'. .- Magic quotes. , .
PHP
.
- 2007 .
if (size > INT_MAX) return NULL; . ( , C: INT_MAX , , . , .) - , PHP 5.3.7
crypt(), . - PHP 5.4 , ..
Content-Length ( ) . .
-, , X — , , .
. ; , .
, . , . , , :)
PHP - ,
Python Flask Web'. ( , .) , , . , , ; web- — .
-
Pyramid Django, , , Django.
, - , ,
Learn Python The Hard Way.
Ruby on Rails , Perl Catalyst' . , , , .
: