How to enable debug() in PHP?



  • I'm having trouble trying to use the function debug(); No PHP.


    In the log apache the following error appears:

    PHP Fatal error: Uncaught Error: Call to undefined function debug() in /var/www/html/...autoload.php:7

    That is, in line 7 of the file autoload.php I put the following test to test if the function is working debug():

    <?php
        //session_start();
        //phpinfo();
        $f = "oi";
        echo $f;
        var_dump($f);
        debug($f);
        die();
    ?>
    

    But without success, has anyone been through this, or do you know how to solve this error?


    Note: I'm using it xdebug-2.6.0beta1


  • QA Engineer

    Because this function is not native to PHP or XDebug, it will not work. As mentioned in the question comments, this is a CakePHP function, however, you can add it to your project.

    To do this just follow the step by step below.

    Adding the function in your project

    1. Download the file https://pastebin.com/Eff17ysa and add in the folder Cake/Error with the name Debugger.php.

    2. Download the file https://pastebin.com/jDQWA7Cs and add in the folder Cake/Log with the name Log.php.

    3. Download the file https://pastebin.com/ZZHnh5Le and add in the folder Cake/Utility with the name Hash.php.

    4. Download the file https://pastebin.com/mueEu8fq and add in the folder Cake/Utility with the name Text.php.

    5. Download the file https://pastebin.com/VMHFMH6A and add in the folder Cake with the name basics.php

    6. Download css file https://pastebin.com/3i1sSMXz and add to your project (Optional).

    Using the function debug in your project

    To use in your project, just follow the code below:

    <?php
    

    spl_autoload_register(function($classname) {
    $file = sprintf("%s.php", $classname);

    if (file_exists($file)) {
        require_once $file;
    } else {
        throw new RuntimeException("File {$file} not found", 404);
    }
    

    });

    require_once "cake/basics.php";

    $json = '[
    {
    "_id": "5a4e7fe189a2b22149d1c7ec",
    "index": 0,
    "guid": "a56c5543-ee29-4cf8-94df-f320eb431f55",
    "isActive": false,
    "balance": "$2,254.23",
    "picture": "http://placehold.it/32x32",
    "age": 24,
    "eyeColor": "green",
    "name": "Rose Stewart",
    "gender": "female",
    "company": "COMTOUR",
    "email": "rosestewart@comtour.com",
    "phone": "+1 (987) 485-2948",
    "address": "107 Schenectady Avenue, Klagetoh, Arkansas, 204",
    "about": "Ipsum sit labore in pariatur sit reprehenderit ut incididunt elit minim amet. Et occaecat est velit deserunt. Nostrud ad laboris adipisicing officia deserunt non sunt tempor qui. Labore anim in eiusmod voluptate nisi nostrud commodo amet cupidatat consectetur nostrud nulla. Culpa nisi Lorem voluptate commodo nisi. Commodo fugiat commodo tempor eiusmod excepteur. Tempor duis eiusmod pariatur reprehenderit.\r\n",
    "registered": "2014-07-02T10:14:10 +03:00",
    "latitude": 25.711449,
    "longitude": 149.030368,
    "tags": [
    "cupidatat",
    "aute",
    "incididunt",
    "Lorem",
    "sunt",
    "in",
    "ipsum"
    ],
    "friends": [
    {
    "id": 0,
    "name": "Traci Duran"
    },
    {
    "id": 1,
    "name": "Tanisha Burris"
    },
    {
    "id": 2,
    "name": "Sherry Kirk"
    }
    ],
    "greeting": "Hello, Rose Stewart! You have 9 unread messages.",
    "favoriteFruit": "apple"
    },
    {
    "_id": "5a4e7fe18afe28b610c8907d",
    "index": 1,
    "guid": "47d8f51f-74b4-4c65-a5be-78b368da58bf",
    "isActive": false,
    "balance": "$2,457.97",
    "picture": "http://placehold.it/32x32",
    "age": 28,
    "eyeColor": "green",
    "name": "Phoebe Bridges",
    "gender": "female",
    "company": "TELLIFLY",
    "email": "phoebebridges@tellifly.com",
    "phone": "+1 (941) 475-3973",
    "address": "374 Centre Street, Aberdeen, District Of Columbia, 1342",
    "about": "Esse consectetur anim nulla ut incididunt exercitation. Fugiat officia ad id elit sunt deserunt exercitation ullamco esse eiusmod elit commodo. Irure in exercitation occaecat irure dolor exercitation. Irure anim in labore ea cupidatat fugiat. Officia tempor elit eiusmod officia labore nostrud cillum ea. Officia reprehenderit elit Lorem Lorem nulla ullamco irure. Nulla esse officia magna cupidatat labore occaecat in labore.\r\n",
    "registered": "2015-10-07T08:16:50 +03:00",
    "latitude": 80.841288,
    "longitude": 102.12139,
    "tags": [
    "excepteur",
    "ut",
    "fugiat",
    "officia",
    "tempor",
    "ad",
    "deserunt"
    ],
    "friends": [
    {
    "id": 0,
    "name": "Stanton Chen"
    },
    {
    "id": 1,
    "name": "Grimes Potts"
    },
    {
    "id": 2,
    "name": "Wilder Pope"
    }
    ],
    "greeting": "Hello, Phoebe Bridges! You have 1 unread messages.",
    "favoriteFruit": "apple"
    },
    {
    "_id": "5a4e7fe1fdf182534ff057a7",
    "index": 2,
    "guid": "abab8774-a1bd-42f1-ba4f-5c3b19c4eb89",
    "isActive": true,
    "balance": "$2,843.88",
    "picture": "http://placehold.it/32x32",
    "age": 37,
    "eyeColor": "green",
    "name": "Reese Jackson",
    "gender": "male",
    "company": "LIQUIDOC",
    "email": "reesejackson@liquidoc.com",
    "phone": "+1 (956) 593-2808",
    "address": "852 Irvington Place, Walland, Mississippi, 7598",
    "about": "Aute quis eu consequat aliqua Lorem id magna ex anim enim esse qui id. In cupidatat voluptate ut Lorem. Laboris ipsum laborum qui in veniam est et fugiat et minim labore.\r\n",
    "registered": "2016-10-11T01:34:32 +03:00",
    "latitude": 28.71233,
    "longitude": 76.544442,
    "tags": [
    "sint",
    "id",
    "velit",
    "sunt",
    "fugiat",
    "nostrud",
    "enim"
    ],
    "friends": [
    {
    "id": 0,
    "name": "Johnston Levy"
    },
    {
    "id": 1,
    "name": "Tisha Bean"
    },
    {
    "id": 2,
    "name": "Roseann Allen"
    }
    ],
    "greeting": "Hello, Reese Jackson! You have 8 unread messages.",
    "favoriteFruit": "strawberry"
    },
    {
    "_id": "5a4e7fe10d545530d9b4290d",
    "index": 3,
    "guid": "80449941-15ce-4734-aee7-42439408d7e7",
    "isActive": true,
    "balance": "$1,746.87",
    "picture": "http://placehold.it/32x32",
    "age": 25,
    "eyeColor": "brown",
    "name": "Gallegos Short",
    "gender": "male",
    "company": "PARAGONIA",
    "email": "gallegosshort@paragonia.com",
    "phone": "+1 (805) 521-2988",
    "address": "462 Hart Place, Lawrence, Alabama, 9109",
    "about": "Dolor occaecat ea do incididunt. Eu sit sit exercitation et quis. Minim officia proident enim enim anim nostrud est eu excepteur veniam in eu culpa. Non sit aute minim nostrud voluptate consectetur deserunt eiusmod enim incididunt id. Commodo aliquip tempor ut ad. Laborum consequat sit ullamco adipisicing consequat occaecat sunt Lorem tempor exercitation nulla deserunt minim. Nulla id elit ea pariatur aliquip elit.\r\n",
    "registered": "2017-05-11T03:32:22 +03:00",
    "latitude": -22.592765,
    "longitude": -118.326613,
    "tags": [
    "nulla",
    "minim",
    "eu",
    "sunt",
    "ut",
    "incididunt",
    "dolor"
    ],
    "friends": [
    {
    "id": 0,
    "name": "Lea Arnold"
    },
    {
    "id": 1,
    "name": "Marla Acosta"
    },
    {
    "id": 2,
    "name": "Bailey Clay"
    }
    ],
    "greeting": "Hello, Gallegos Short! You have 8 unread messages.",
    "favoriteFruit": "strawberry"
    },
    {
    "_id": "5a4e7fe169ab13c7ca60517d",
    "index": 4,
    "guid": "fb83500c-4fa0-4146-8bdf-3363b66cdd9a",
    "isActive": false,
    "balance": "$3,613.46",
    "picture": "http://placehold.it/32x32",
    "age": 39,
    "eyeColor": "blue",
    "name": "Rivers Ayers",
    "gender": "male",
    "company": "QUANTASIS",
    "email": "riversayers@quantasis.com",
    "phone": "+1 (958) 479-3701",
    "address": "384 Albee Square, Noxen, Texas, 5220",
    "about": "Magna id ea in sint. Veniam esse duis ipsum commodo dolor laboris ea ut irure ea. Sunt culpa deserunt labore dolore eu ad esse amet quis excepteur deserunt laborum elit. Elit eiusmod veniam pariatur aute duis sint id et velit proident tempor commodo ut sint.\r\n",
    "registered": "2015-09-08T09:24:58 +03:00",
    "latitude": -79.499936,
    "longitude": 19.478766,
    "tags": [
    "sint",
    "mollit",
    "dolor",
    "tempor",
    "adipisicing",
    "exercitation",
    "quis"
    ],
    "friends": [
    {
    "id": 0,
    "name": "Brandie Stevens"
    },
    {
    "id": 1,
    "name": "Matilda Barber"
    },
    {
    "id": 2,
    "name": "Pat Le"
    }
    ],
    "greeting": "Hello, Rivers Ayers! You have 3 unread messages.",
    "favoriteFruit": "banana"
    },
    {
    "_id": "5a4e7fe191c95b83d579b6c7",
    "index": 5,
    "guid": "2695c3ef-c4ec-4bd8-90b6-cd9384dd615a",
    "isActive": true,
    "balance": "$1,350.94",
    "picture": "http://placehold.it/32x32",
    "age": 29,
    "eyeColor": "brown",
    "name": "Olga England",
    "gender": "female",
    "company": "GENMEX",
    "email": "olgaengland@genmex.com",
    "phone": "+1 (824) 416-2274",
    "address": "993 Garnet Street, Calpine, Virgin Islands, 8308",
    "about": "Velit ipsum labore veniam voluptate quis duis in laboris irure nisi deserunt magna. Anim irure quis aute pariatur. Magna proident do reprehenderit commodo duis sit. Est reprehenderit dolor commodo nostrud commodo minim tempor aute irure elit. Esse nisi excepteur ex excepteur sunt enim sint et duis velit proident. Do nisi nisi duis ipsum consequat nulla ipsum voluptate.\r\n",
    "registered": "2015-08-30T09:19:52 +03:00",
    "latitude": 21.195056,
    "longitude": -148.916229,
    "tags": [
    "ad",
    "id",
    "cillum",
    "nisi",
    "fugiat",
    "consectetur",
    "magna"
    ],
    "friends": [
    {
    "id": 0,
    "name": "Herminia Parker"
    },
    {
    "id": 1,
    "name": "Louisa Bennett"
    },
    {
    "id": 2,
    "name": "Cross Hatfield"
    }
    ],
    "greeting": "Hello, Olga England! You have 8 unread messages.",
    "favoriteFruit": "banana"
    }
    ]';

    debug( json_decode($json) );


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2