PHP
PHP Basics

0: Introduction
1: How to set up PHP
2: How to create your first PHP program
3: How to deal with errors in PHP
4: How to use exceptions in PHP
5: How to use Composer and Packagist in PHP
6: How to work with files/folders in PHP
7: ▶︎ PHP print var_dump to error_log

[← back to the Valley]

PHP Basics: PHP print var_dump to error_log

Here’s a piece of code I’ve been using when debugging PHP.

I want to print a value to the error log using error_log(), but it only accepts strings.

So I used this snippet to print the result of a var_dump():

ob_start();
var_dump($something);
$contents = ob_get_contents();
ob_end_clean();
error_log($contents);
◀︎ How to work with files/folders in PHP

Lessons in this unit:

0: Introduction
1: How to set up PHP
2: How to create your first PHP program
3: How to deal with errors in PHP
4: How to use exceptions in PHP
5: How to use Composer and Packagist in PHP
6: How to work with files/folders in PHP
7: ▶︎ PHP print var_dump to error_log

Join my AI Workshop!

The Web Development BOOTCAMP cohort starts in February 2026