PHP debugging in der Javascript console

Eine Aufgabe die einem immer mal wieder über den weg läuft ist das man bei einem Fertigen Produkt, nachträglich etwas debuggen muss. Nun kann man nicht einfach an der Live Version herum doktern und irgendetwas ausgeben. Hier kann einem die JavaScript console helfen. Diese ist für den normalen Nutzern nicht sichtbar und somit wunderbar geeignet für diesen Job.  Hier mal ein kleines beispiel wie eine solche debug Klasse aus sehen könnte.



class DebugConsole {
    public static function debug($name, $var = null) {
        echo '<script type="text/javascript">'.PHP_EOL ;

        /// this is for IE and other browsers w/o console
        echo 'if (!window.console) console = {};';
        echo 'console.log = console.log || function(){};';
        /// end of IE    

        echo 'console.log("'.$name.'");'.PHP_EOL ;    

        if (!empty($var)) {
            if (is_object($var) || is_array($var)) {
                $object = json_encode($var);
                echo 'var object'.preg_replace('~[^A-Z|0-9]~i',"_",$name).' = \''.str_replace("'","\'",$object).'\';'.PHP_EOL ;
                echo 'var val'.preg_replace('~[^A-Z|0-9]~i',"_",$name).' = eval("(" + object'.preg_replace('~[^A-Z|0-9]~i',"_",$name).' + ")" );'.PHP_EOL ;
                echo 'console.log(val'.preg_replace('~[^A-Z|0-9]~i',"_",$name).');'.PHP_EOL ;    

            } else {
                echo 'console.log("'.str_replace('"','\\"',$var).'");'.PHP_EOL ;
        echo '</script>'.PHP_EOL ;

18 Antworten zu “PHP debugging in der Javascript console”

  1. Gingerwo28u sagt:
    Purchasing a new or used vehicle might be a challenging process if you do not know what you really are carrying out. By educating yourself about vehicle buying before you decide to go to the dealership, you can make points less difficult on your own. The following tips can help the next store shopping getaway be satisfying.

    Always provide a auto technician coupled when searching for a fresh vehicle. Auto retailers are well known for promoting lemons and you do not wish to be their after that target. Provided you can not have a mechanic to look at automobiles along with you, no less than make certain you have him take a look at ultimate selection before buying it.

    Know your limits. Before starting buying for your next vehicle or van, determine how much you can afford to spend, and stay with it. Don’t forget about to incorporate fascination with your estimations. You can expect to shell out around 20 % as a payment in advance as well, so be ready.

    Just before visiting a dealer, know which kind of motor vehicle you would like. Analysis all you possibilities prior to purchasing to help you determine what works for your financial allowance and family requires. Shop around to determine exactly how much you need to be paying for a prospective automobile.

    Before you sign any commitment spend some time to read through every line, for example the fine print. If you find nearly anything outlined that you simply do not comprehend, usually do not indication before you get an response that you fully grasp. Unsavory salesmen can make use of an agreement to put in several costs that have been not mentioned.

    When you maintain the previous advice in your mind the next time that you simply go purchasing a auto, you will certainly be more likely to get a full package. Getting a automobile lacks as a headache. Just use the ideas out of this post and you may receive the auto you want at the very good cost.

  2. site sagt:

    Hello there I am so glad I found your website, I really
    found you by accident, while I was looking on Yahoo for something else, Regardless
    I am here now and would just like to say kudos for a
    incredible post and a all round exciting blog (I also love the theme/design), I don’t
    have time to browse it all at the minute but I have bookmarked it and also
    included your RSS feeds, so when I have time I will be back to read more,
    Please do keep up the great work.

  3. Aarondus sagt:

    Junge Madchen wollen Sex in deiner Stadt:

  4. A good blog! I will bookmark a few of these.. Lilia Maury Moia

  5. Jamesqualo sagt:

    Please sent all ads and promo information by

  6. Holographicgfk sagt:

    Libraries of the Carolingian era). IN

  7. Dormanahb sagt:

    From many manuscripts of Antiquity

  8. Flashpaqbps sagt:

    Manuscript is a collective name for texts

  9. Pouringssi sagt:

    from lat. manus – „hand“ and scribo – „I write“) [1]

  10. Interfaceflx sagt:

    drafts of literary works

  11. Vortexwfh sagt:

    scroll. Go to Code Form

  12. Speakerwfc sagt:

    consists of the book itself

  13. Superchipsuif sagt:

    bride, Julie d’Angenne.

  14. Mojavexym sagt:

    bride, Julie d’Angenne.

  15. WILDKATqda sagt:

    Century to a kind of destruction:

  16. Sightlhl sagt:

    from lat. manus – „hand“ and scribo – „I write“) [1]

  17. buroindubre sagt:

    exchanger binance a bitcoin Shibainu
    usdt opencart Dash
    exchanger solidtrust to dash Bitcoin
    get bitcoins with sms Bitcoin

Schreibe einen Kommentar