#35727 [Opn->Csd]: magic constant __CALLED_FROM__

From: Date: Sun, 18 Dec 2005 23:46:08 +0000
Subject: #35727 [Opn->Csd]: magic constant __CALLED_FROM__
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-90626@lists.php.net to get a copy of this message
ID: 35727 Updated by: helly@php.net Reported By: erm at the-erm dot com -Status: Open +Status: Closed Bug Type: Feature/Change Request Operating System: any PHP Version: 5.1.1 New Comment: Nothing to do here: Use debug_backtrace() Previous Comments: ------------------------------------------------------------------------ [2005-12-18 23:10:09] erm at the-erm dot com Description: ------------ Please add a new magic constant like __FUNCTION__ only it displays what function the current function was called from. This would be good for debugging, and an error handleling function. Reproduce code: --------------- // I know die could do it. This is just an example function error($error) { echo "There was an error in '".__CALLED_FROM__." '$error"; } function normal($arg) { // For debuging: echo __FUNCTION__.'called from:'.__CALLED_FROM__."\n"; echo $arg; } function call_normal() { normal("Some Text\n"); } function call_normal_again() { normal("Other Text\n"); } normal("hi\n";); call_normal(); call_normal_again(); error("No Error\n"); Expected result: ---------------- normal called from: hi normal called from:call_normal Some Text normal called from:call_normal_again Other Text There was an error in '' No Error My examples are pretty basic, but I can see where a magic constant like __CALLED_FROM__ could be very useful. You could use it to make sure that the data that a function is getting fed is the right data, and if there's an error report what function did the call. So then you can fix it faster, and more efficiently. Thanks ahead of time for adding it, and if not thanks for your time. Actual result: -------------- n/a ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=35727&edit=1

« previous php.bugs (#90626) next »