By default, displaying errors is turned off because you don't want a "customer" seeing the error messages.

Check this page in the PHP documentation for information on the 2 directives: error_reporting and display_errors. display_errors is probably the one you want to change.

So you have 3 options:

(1) You can check the error log file as it will have all of the errors (unless logging has been disabled). To enable error logging make sure that log_errors configuration directive is set to On. Logs are also helpful when error is happened not in PHP but emitted by web-server.

(2) You can add the following 2 lines that will help you debug errors that are not syntax errors happened in the same file:

error_reporting(E_ALL);
ini_set('display_errors', 'On');

Note that on a live server the latter should be set to Off (but only the latter, because you still need to learn about all errors happened, from the log file).

However, for syntax errors happened in the same file, the above commands won't work and you need to enable them in the php.ini. If you can't modify the php.ini, you may also try to add the following lines to an .htaccess file, though it's seldom supported nowadays:

php_flag  display_errors        on
php_value error_reporting       -1

(3) Another option is to use an editor that checks for errors when you type, such as PhpEd, VSCode or PHPStorm. They all come with a debugger which can provide more detailed information. (The PhpEd debugger is very similar to xdebug and integrates directly into the editor so you use 1 program to do everything.)

Answer from Darryl Hein on Stack Overflow
🌐
GitHub
github.com › php › php-src
GitHub - php/php-src: The PHP Interpreter
Additional extensions can be found in the PHP Extension Community Library - PECL. The PHP source code is located in the Git repository at github.com/php/php-src.
Starred by 40K users
Forked by 8K users
Languages   C 69.8% | PHP 27.8% | C++ 0.9% | M4 0.4% | Shell 0.3% | Lua 0.2%
Top answer
1 of 16
538

By default, displaying errors is turned off because you don't want a "customer" seeing the error messages.

Check this page in the PHP documentation for information on the 2 directives: error_reporting and display_errors. display_errors is probably the one you want to change.

So you have 3 options:

(1) You can check the error log file as it will have all of the errors (unless logging has been disabled). To enable error logging make sure that log_errors configuration directive is set to On. Logs are also helpful when error is happened not in PHP but emitted by web-server.

(2) You can add the following 2 lines that will help you debug errors that are not syntax errors happened in the same file:

error_reporting(E_ALL);
ini_set('display_errors', 'On');

Note that on a live server the latter should be set to Off (but only the latter, because you still need to learn about all errors happened, from the log file).

However, for syntax errors happened in the same file, the above commands won't work and you need to enable them in the php.ini. If you can't modify the php.ini, you may also try to add the following lines to an .htaccess file, though it's seldom supported nowadays:

php_flag  display_errors        on
php_value error_reporting       -1

(3) Another option is to use an editor that checks for errors when you type, such as PhpEd, VSCode or PHPStorm. They all come with a debugger which can provide more detailed information. (The PhpEd debugger is very similar to xdebug and integrates directly into the editor so you use 1 program to do everything.)

2 of 16
473

The following enables all errors:

ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
error_reporting(-1);

Also see the following links

  • http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors
  • http://php.net/manual/en/errorfunc.configuration.php#ini.display-startup-errors
  • http://php.net/manual/en/function.error-reporting.php
Discussions

What does double question mark (??) operator mean in PHP - Stack Overflow
I was diving into Symfony framework (version 4) code and found this piece of code: $env = $_SERVER['APP_ENV'] ?? 'dev'; I'm not sure what this actually does but I imagine that it expands to someth... More on stackoverflow.com
🌐 stackoverflow.com
What is PHP and why do I need to learn it?
PHP is a programming language that was used to make websites and applications (and is still used). It uses a system named CGI (common gateway interface) to generate HTML dynamically, this is why it was wide adopted by the industry (20 years ago). More tools and languages were developed without the problems that PHP has. The most important? Bad programmers making shit code. This added to old PHP learning resources affected to the language community. Today, thanks to frameworks like Laravel, PHP is used for small and mid-applications. It (Laravel) improves a lot the developer experience. In my opinion I don't like PHP, I prefer other tools to make web applications. But is one of the most used programming languages. There are a lot of jobs and companies using this language. You don't have to learn PHP specifically, but when you are developing the backend of a website is one of the options that you can choose. More on reddit.com
🌐 r/AskProgramming
57
5
January 8, 2024
How do I get PHP errors to display? - Stack Overflow
No messing around with .htaccess or php.ini. When you're done, just comment it out or remove it. PHP 7.4 2020-10-23T14:18:41.2Z+00:00 ... This is the best way to write it, but a syntax error gives blank output, so use the console to check for syntax errors. The best way to debug PHP code is to ... More on stackoverflow.com
🌐 stackoverflow.com
Formatting PHP code in vscode, using prettier, on save

No one should ever format on save, on projects where you work in a team, it will be an never ending whitespace war. And it will seriously pollute your VCS diff's with unrelated whitespace changes, and potentially create conflicts along the way. Please don't.

The only valid use case of reformatting on save is when it's a project requirement, everyone uses the same tooling, editor, and formatting rules. Under any other scenario, please don't.

More on reddit.com
🌐 r/PHP
27
24
October 29, 2017
🌐
Sathyabama Institute of Science and Technology
sathyabama.ac.in › sites › default › files › course-material › 2020-10 › UNIT4.pdf pdf
4.1 Introduction to PHP & Features 4.2 PHP Scripts 4.3 ...
The PHP increment operators are used to increment a variable's value. ... The PHP decrement operators are used to decrement a variable's value. ... The PHP logical operators are used to combine conditional statements. ... PHP has two operators that are specially designed for strings. ... The PHP array operators are used to compare arrays. ... The if statement executes some code if one condition is true.
Top answer
1 of 3
668

It's the "null coalescing operator", added in php 7.0. The definition of how it works is:

It returns its first operand if it exists and is not NULL; otherwise it returns its second operand.

So it's actually just isset() in a handy operator.

Those two are equivalent1:

bar ?? 'something';
$foo = isset(bar : 'something';

Documentation: http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce

In the list of new PHP7 features: http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op

And original RFC https://wiki.php.net/rfc/isset_ternary


EDIT: As this answer gets a lot of views, little clarification:

1There is a difference: In case of ??, the first expression is evaluated only once, as opposed to ? :, where the expression is first evaluated in the condition section, then the second time in the "answer" section.

2 of 3
55
$myVar = $someVar ?? 42;

Is equivalent to :

$myVar = isset($someVar) ? $someVar : 42;

For constants, the behaviour is the same when using a constant that already exists :

define("FOO", "bar");
define("BAR", null);

$MyVar = FOO ?? "42";
$MyVar2 = BAR ?? "42";

echo $MyVar . PHP_EOL;  // bar
echo $MyVar2 . PHP_EOL; // 42

However, for constants that don't exist, this is different :

$MyVar3 = IDONTEXIST ?? "42"; // Raises a warning
echo $MyVar3 . PHP_EOL;       // IDONTEXIST

Warning: Use of undefined constant IDONTEXIST - assumed 'IDONTEXIST' (this will throw an Error in a future version of PHP)

Php will convert the non-existing constant to a string.

You can use constant("ConstantName") that returns the value of the constant or null if the constant doesn't exist, but it will still raise a warning. You can prepended the function with the error control operator @ to ignore the warning message :

$myVar = @constant("IDONTEXIST") ?? "42"; // No warning displayed anymore
echo $myVar . PHP_EOL; // 42
🌐
W3Schools
w3schools.com › php › php_syntax.asp
PHP Syntax
Loops While Loop Do While Loop For Loop Foreach Loop Break Statement Continue Statement PHP Functions PHP Arrays · Arrays Indexed Arrays Associative Arrays Create Arrays Access Array Items Update Array Items Add Array Items Remove Array Items Sorting Arrays Multidimensional Arrays Array Functions PHP Superglobals
🌐
W3Schools
w3schools.com › php › php_examples.asp
PHP Examples
Write text to the output using PHP Keywords, classes, functions, and user-defined functions ARE NOT case-sensitive Variable names ARE case-sensitive ... Single-line comment before code line Single-line comment at the end of code line Use comment to prevent code from being executed Multi-line comment Multi-line comment to ignore code ... Create variables Output some text and the value of a variable Output the sum of two variables Assign the same value to multiple variables in one line Use var_dump() to return the data type of variables Global scope (variable outside function) Local scope (variable inside function) Static scope (let a local variable not be deleted after execution of function) Use the global keyword to access a global variable from within a function Use the $GLOBALS[] array to access a global variable from within a function
Find elsewhere
🌐
Wikipedia
en.wikipedia.org › wiki › PHP
PHP - Wikipedia
3 days ago - On a web server, the result of the interpreted and executed PHP code—which may be any type of data, such as generated HTML or binary image data—can form the whole or part of an HTTP response. Various web template systems, web content management systems, and web frameworks exist that can be employed to orchestrate or facilitate the generation of that response.
🌐
PHP
php.net
PHP
PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.
🌐
W3Schools
w3schools.com › php › php_operators.asp
PHP Operators
Loops While Loop Do While Loop For Loop Foreach Loop Break Statement Continue Statement PHP Functions PHP Arrays · Arrays Indexed Arrays Associative Arrays Create Arrays Access Array Items Update Array Items Add Array Items Remove Array Items Sorting Arrays Multidimensional Arrays Array Functions PHP Superglobals
🌐
Visual Studio Code
code.visualstudio.com › docs › languages › php
PHP in Visual Studio Code
November 3, 2021 - Learn about Visual Studio Code editor features (syntax highlighting, snippets, linting) and extensions for PHP.
🌐
Codecademy
codecademy.com › catalog › language › php
PHP Courses & Tutorials | Codecademy
Learn how to make your own classes and initialize objects based on the defined classes. ... Write programs that handle complex decision-making using the boolean data type, conditionals, and comparison and logical operators. ... Learn how to use for-loops and while-loops to execute the same code multiple times. ... Use your PHP ...
🌐
BairesDev
bairesdev.com › tools › phpcodechecker
PHP Code Checker - Syntax Check for Common PHP Mistakes
An advanced, custom PHP code checker that searches your code for common, hard to find typos and mistakes; includes a syntax check.
🌐
Reddit
reddit.com › r/askprogramming › what is php and why do i need to learn it?
r/AskProgramming on Reddit: What is PHP and why do I need to learn it?
January 8, 2024 -

Right now, I am learning what front-end development is and how to use it, as well as using HTML with JavaScript and CSS. In this stage, I am noticing PHP pop up more and more, especially since I'm using WordPress more often. I understand that it is a scripting language, but I am failing to understand its actual usage and application. So, what is a detailed explanation of it?

Top answer
1 of 16
3675

DEV environment

This always works for me:

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

However, this doesn't make PHP to show parse errors occurred in the same file. Also, these settings can be overridden by PHP. In these cases the only way to show those errors is to modify your php.ini (or php-fpm.conf) with this line:

display_errors = on

(if you don't have access to php.ini, then putting this line in .htaccess might work too):

php_flag display_errors 1

PROD environment

Note that above recommendation is only suitable for the DEV environment. On a live site it must be

display_errors = off
log_errors = on

And then you'll be able to see all errors in the error log. See Where to find PHP error log

AJAX calls

In case of AJAX call, on a DEV server, open DevTools (F12), then Network tab. Then initiate the request which result you want to see, and it will appear in the Network tab. Click on it and then the Response tab. There you will see the exact output.

While on a live server just check the error log all the same.

2 of 16
167

You can't catch parse errors in the same file where error output is enabled at runtime, because it parses the file before actually executing anything (and since it encounters an error during this, it won't execute anything). You'll need to change the actual server configuration so that display_errors is on and the approriate error_reporting level is used. If you don't have access to php.ini, you may be able to use .htaccess or similar, depending on the server.

This question may provide additional info.

🌐
PHPGurukul
phpgurukul.com › home › php projects free downloads
Free PHP Projects with Source Code, Download PHP Project Free for beginners
October 9, 2016 - This list of projects in PHP with source code aims to enhance the user’s skills with the dynamic and attractive web application. These PHP projects are well designed for users to understand the PHP concept during the execution of any web development. And it could also be helpful for students ...
🌐
Codecademy
codecademy.com › home › what is php used for?
PHP Intro: What Is It Used For?
March 3, 2025 - Below, we’ll take a closer look at PHP, how it works, its relationship with HTML, examples of PHP in action, and more. Within PHP code operating a website, variables and ordered and associative arrays can be managed.
🌐
Code Institute
codeinstitute.net › blog › programming › a comprehensive guide to php programming: what you need to know
What is PHP? Uses & Introduction - Code Institute Global
October 23, 2023 - PHP is an open-source, server-side programming language that can be used to create websites, applications, customer relationship management systems and more. It is a widely-used general-purpose language that can be embedded into HTML. This functionality with HTML means that the PHP language has remained popular with developers as it helps to simplify HTML code.
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-tutorial
PHP Tutorial - GeeksforGeeks
August 13, 2025 - Once your environment is ready, we’ll explore the core concepts that will form the foundation of your PHP skills. Learn how to write dynamic web applications, manage variables, perform type casting, and work with control structures. ... Functions are key to creating efficient and reusable code. This section will teach you how to create functions in PHP, from basic functions to more advanced anonymous and variadic functions.