Все сталкиваются с ошибками. Даже опытные программисты допускают опечатки. Возникают, например, синтаксические ошибки. Это ряд ответов о предупреждениях, ошибках и уведомлениях, с которыми вы можете столкнуться при программировании на PHP и не знаете, как их исправить.
Особенно часто проблемы с пониманием возникают у русскоязычного разработчика, т.к. все сообщения на ̶э̶л̶ь̶ф̶и̶й̶с̶к̶о̶м̶ английском, поэтому данные пояснения будут особо полезны.
Ссылки на другие способы нахождения ожибок:
Найдите ошибку в списке ниже и перейдите к ответу с её описанием.
P.S. Ошибки выделены в группы не по контексту и логической принадлежности, а для того, чтобы не плодить по одному ответу на каждую ошибку.
- Общие предварительные проверки.
- Ничего не видно. Страница пустая и белая.
- Код не запускается / Выводится код как он есть в PHP
- Notice: Undefined variable / Notice: Undefined property
- Warning: [function] expects parameter 1 to be resource, boolean given
- Warning: [function]: failed to open stream
- Warning: Division by zero
- Warning: Illegal string offset 'XXX' | Uncaught TypeError: Cannot access offset of type string on string (PHP 8.0)
- Warning: count(): Parameter must be an array or an object that implements Countable
- Fatal error: Call to a member function ... on a non-object
- Fatal error: Call to undefined function XXX
- Fatal error: Cannot redeclare class [class name] / Fatal error: Cannot redeclare [function name]
- Fatal error: Can't use function return value in write context
- Fatal error: Declaration of AAA::BBB() must be compatible with that of CCC::BBB()
- Fatal error: Using $this when not in object context
- Fatal error: Object of class Closure could not be converted to a string
- Fatal error: Undefined class constant
- Fatal error: Uncaught TypeError: some_function(): Argument #1 must be of type XXX, YYY given
- Notice: Array to string conversion
- Notice: Trying to get property of non-object error
- Notice: Undefined Index (Undefined array key) / Undefined offset
- Notice: Uninitialized string offset: XXX
- Notice: Use of undefined constant XXX - assumed 'XXX' / Warning: Use of undefined constant XXX - assumed 'XXX' (this will throw an Error in a future version of PHP)
- Strict Standards: Non-static method [<class>::<method>] should not be called statically
- Warning: function() expects parameter XXX to be boolean (or integer, string, etc), YYY given
- Deprecated: Array and string offset access syntax with curly braces is deprecated