yan-k
10/18/2015 - 8:06 PM

wordpress-debugging-classes.php

<?php
 
class My_Class {
    public function my_func() {
        // We can error log our data here.
        error_log( __LINE__ ); // outputs 6
 
        // Or we can also log which method we're in
        error_log( __METHOD__ ); // outputs My_Class::my_func
    }
}
 
function my_function() {
    // With functions, you can also log their function name
    error_log( __FUNCTION__ ); // outputs my_function
}
 
function log_this(){
    // You can also combine them, here is a basic example
    error_log( sprintf( '%s - %s::%d', date( 'F j Y', time() ), __FUNCTION__, __LINE__ ) );
    // Will output something like August 1, 2015 - log_this::21
}