I can't even say what's wrong with PHP, because ... Okay. Imagine, um, a box of tools. Set of tools. Looks fine, tools like tools.
You take a screwdriver and see a cross with three petals. Okay, not very useful for you, but it may someday be needed.
Take the hammer and are horrified that it is bifurcated on both sides. Of course, it is still suitable, I mean, that you can hammer in nails in the middle of the striker, holding the handle in reverse.
Take pliers that do not have chipping; they are flat and smooth. Not as useful as it could be, but they can still unscrew the bolts.
And so on. All tools are something strange and twisted, but not enough to be completely useless. And in the whole set there is no specific problem; it has all the tools.
Now imagine millions of carpenters using such a set of tools and telling you: “What's wrong with these tools? I have never used anything else and they work great! ” And the carpenters show you the houses they built with pentagonal rooms and a roof upside down. You knock on the door, it just falls inside and they yell at you for breaking their door.
That's what's wrong with PHP.
mysql_real_escape_string
, E_ACTUALLY_ALL
strpos
, str_rot13
===
==
, foreach ($foo as &$bar)
+
:, , '==' (?), 'eq'. , PHP, , , .
(int)
C, int
. \
. -: [key=>value]
.@fopen('http://example.com/not-existing-file', 'r');
--disable-url-fopen-wrapper
, . ( , « »; null, ?) , PHP 5.2.5.allow_url_fopen
php.ini, . ( ? .)@
, .scream.enabled
php.ini.scream.enabled
ini_set
.error_reporting
.display_errors
, php.ini. ini_set
.mbstring
. func_get_arg
, . . register_tick_function
, — ?!fork
( ), .json_decode
null , , null — JSON'. , json_last_error
.array_search
, strpos
0
, , false .strpos
-1
, . , . ( . C. . , .).index
, . , .FALSE
, ===
, PHP 0
. ; , strpos
.==
NULL < -1
, NULL == 0
. ; , .==
, ===
. <
… . "123" < "0124"
, , .+
, +
, .
.[]
{}
.[]
, . null .[]
; .foo()[0]
— . ( PHP 5.4.)?:
. :$arg = 'T';
$vehicle = ( ( $arg == 'B' ) ? 'bus' :
( $arg == 'A' ) ? 'airplane' :
( $arg == 'T' ) ? 'train' :
( $arg == 'C' ) ? 'car' :
( $arg == 'H' ) ? 'horse' :
'feet' );
echo $vehicle;
horse
.global
. , , — PHP . .$x = new SplBool(true); $x = "foo";
. -, .use constant
.)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;
.@
( DOS) .::
T_PAAMAYIM_NEKUDOTAYIM
, <<
T_SL
. «», , , ::
<<
.E_STRICT
, , , .E_ALL
— E_STRICT
.E_STRICT
, :$foo->x
.(warning)2 < "foo"
( )foreach (2 as $foo);
(warning)$foo::x
. (fatal error)list
. (parse error)foo()[0]
. (parse error, 5.4, . )__toString
. PHP… , . ( fatal error, .)trigger_error
) try
/catch
.set_error_handler
.set_exception_handler
, try
mod_php
.new ClassDoesntExist()
) . fatal error', . Shutdown- , ( ), .finally
, wrapper-( , , ; , , ) . , Java, , finally
« PHP». ?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...
string
. ReflectionParameter::getClass()
, type hint , , .call_user_func_array(' ', func_get_args())
. func_get_args
fatal error , , func_get_args
. ? ( PHP 5.3.)&
.func_num_args
, func_get_arg
func_get_args
. .getFoo
Java-. , ? Perl, Python Ruby: - «» ; PHP __get
. Java, , - PHP, .instanceof
, , . Java? first-class ?is_a
. , .get_class
; typeof
. is_subclass_of
.instanceof
(, int
). is_int
.clone
— ?!$obj->foo
, $obj::foo
. .Class::method
). (. ) $this
.new
, private
, public
, protected
, static
. Java-? , , — C++ .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
.strpos
/str_rot13
, php_uname
/phpversion
, base64_encode
/urlencode
, gettype
/get_class
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_
. .DOM
(-), DOM XML
( -), libxml
, SimpleXML
, «XML Parser», XMLReader
/XMLWriter
, . - , .mysql
, mysqli
PDO
.mysql_real_escape_string
, , mysql_escape_string
, MySQL C API.dba_nextkey
dba_firstkey
segfault'.ctype_*
( ctype_alnum
) C- , , , isupper
.sort {$b <=> $a}
. Python .sort(reverse=True)
. PHP, rsort()
.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
.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.compact
extract
— .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
: , , , , , .0
, 012
. , 08
. 8
( 9
) . 01c
.pi
— . , M_PI
.pow
.mbstring
, .Ă©
É
."$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
, .array("foo", "bar") != array("bar", "foo")
array("foo" => 1, "bar" => 2) == array("bar" => 2, "foo" => 1)
array_fill
, false.array_reverse
.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
. .php.ini
PHP , . PHP- , , php.ini
.mod_rewrite
, FastCGI, Server:
.<?php ... ?>
, , ( «headers already sent»). — ?>
; PHP .php.ini
PHP-, . php.ini
; shared- , , ; ini_set
, Apache .htaccess
. . , , ..svn
) . mod_php
; , , URL .SetHandler
.php
- PHP, AddHandler
, Google AddHandler
. .AddHandler
, Apache, « php» — .php
-. ! Apache , . , , index.html.en
, HTML- . Apache ..php
. , foo.php.txt
; , Apache PHP, .+x
, -, PHP . ; .htmlspecialchars
» — XSS-. XSS-.mod_rewrite
( .htaccess
) ."<script>"
SQL, HTML.addslashes
, stripslashes
- — , .pcntl_fork
pcntl_exec
.escapeshellcmd
escapeshellarg
. , Windows, escapeshellarg
(.. Bourne shell), escapeshellcmd
, Windows cmd ( , ).sprintf
is_numeric
, mysql_real_escape_string
, addslashes
( « »!). PDO , . PHP . , … .register_globals
. , PHP 5.4. . .include
HTTP URL'. .if (size > INT_MAX) return NULL;
. ( , C: INT_MAX
, , . , .)crypt()
, .Content-Length
( ) . .Source: https://habr.com/ru/post/142140/
All Articles