Wyświetlanie zmiennej w PHP
To debug variables in PHP – probably the most popular programming language for web services, it is sometimes useful to have your own functions for displaying the contents of variables in any places in the code. I recommend using my _e() function, which will allow you to display the values we are interested in in PHP scripts:
What is debugging?
Debugging, from the word bug, refers to an error. Word creation belongs to the nondescript Grace Hopper when, while working on the Mark II computer at Harvard University, her colleagues found a moth that had become entangled in the transmitter, preventing the equipment from working. Admiral Hopper called finding a dead insect in the machine debugging, i.e. deworming. However, this term as a concept was already known much earlier. It was already used in 1878 by Thomas Edison, who in one of his letters described it with the word bugs – i.e. technical faults.
function getVarName($var) { foreach($GLOBALS as $var_name => $value) { if ($value === $var) { return $var_name; } } return false; }
function _e($var, $die = null) { $var_txt = '$'.getVarName($var); echo '<div style="z-index:9998;padding: 10px;background-color:red"><div style="z-index:9999;padding: 30px;color:white;background-color:green"><h2>Contents of '.$var_txt.'</h2><hr style="border-color:white;color:white"><pre>'; var_dump($var);echo '---<br />'; print_r($var); echo '</pre><hr style="border-color:white;color:white">'; echo('End of contents for '.$var_txt.'</div></div>'); $die == 'die' ? die() : null ; }
_e($smarty,'die'); //zatrzymuje skrypt po wyswietleniu zawartosci zmiennej _e($smarty); //tylko wyswietla zmienna $smarty