Debugging functions in Ruby versus PHP
So far, we’ve made scripts and code snippets making sure that our code works correctly every time. However, in the real world, we’ll come into contact with code that someone else has created and either wasn’t tested, or it wasn’t tested in a scenario that hadn’t come up until now. This happens more often than not, and we should be prepared to get our hands dirty to fix these types of issues. In PHP, we have a couple of functions that will help us debug in the simplest way. You are welcome to just read the following example and not follow along. For now, let’s take a look at PHP’s var_dump()
function. We can open a command shell and create a file with the following content:
<?php //buggy_code.php $person['firSt'] = 'Thomas'; $person['last'] = 'Anderson'; echo "Hi {$person['first']} {$person['last']}";
Let’s say we...