Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Да вот хоть тот же пример со ссылкой перед echo. С какой стати это вообще должно работать? А ведь работает.Оно также работает и в C, C++ и C#. При некоторых условиях заработает в Java. так что ничего удивительного в том, что оно работает еще и в PHP — нет.
@ для игнорирования ошибок и мне приходилось отлаживать чужой код… который им активно пользовался.
<?php
@strpos();
echo $php_errormsg; // Wrong parameter count for strpos()
<?php
class A {
const C = B::C;
}
class B {
const C = A::C;
}
var_dump(A::C);
Fatal error: Cannot declare self-referencing constant 'B::C' in /Users/nasretdinov/fails.php on line 10
<?php
class A {
const C = SOMETHING;
}
var_dump(A::C);
Notice: Use of undefined constant SOMETHING - assumed 'SOMETHING' in /Users/nasretdinov/something.php on line 6
string(9) "SOMETHING"
<?php
class A {
const C = SOMETHING;
}
define('SOMETHING', "Value of something constant");
var_dump(A::C); // выведет string(27) "Value of something constant"
Ведь мы обращались к константе класса «A::C», а ошибку получили про то, что константа SOMETHING не определена.
Warning Reference of a $value and the last array element remain even after the foreach loop. It is recommended to destroy it by unset().
The closest analogy is with Unix filenames and files — variable names are directory entries, while variable content is the file itself. References can be likened to hardlinking in Unix filesystem.
What References are not: References.
References are opaque things that are like pointers, except A) smarter and B) referring to HLL objects, rather than memory addresses. PHP doesn't have references. PHP has a syntax for creating *aliases* which are multiple names for the same object. PHP has a few pieces of syntax for calling and returning «by reference», which really just means inhibiting copying. At no point in this «references» section of the manual are there any references.
<?php
http://google.com
echo 3 + 5;
# http: - лейбл. метка на которую можно зайти через goto
// - комментарий
http: // все что угодно
goto http;
$cnt = getCount( $foo['bar'] );
var_dump($foo); //внезапно ['bar' => null]
${""} = 444;
${" "} = 555;
var_dump(${""},${" "});
$x = 0;
$y = ' ';
//$y = '.';
//$y = '-';
//$y = '0x0';
//$y = 'sdfhsdkhfkjsdhfdksj';
$x == $y; //true
$a = 1;
var_dump ($a + ($a = 2));
int 4 - все верно
$a = 1;
var_dump ($a + $a + ($a = 2));
ErrorException [ Fatal Error ]: Unsupported operand types
$a = 1;
if (($a + $a + ($a = 2)) == 2)
echo '==';
==
все дело в оптимизации (может быть), но как минимум все дело в том, как хранятся переменные.Дело совсем не в оптимизации, а в приоритетах операций и последовательности их обработки.
Безумный PHP. Фьюри код