php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #35727 magic constant __CALLED_FROM__
Submitted: 2005-12-18 23:10 UTC Modified: 2005-12-19 00:46 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: erm at the-erm dot com Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 5.1.1 OS: any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: erm at the-erm dot com
New email:
PHP Version: OS:

 

 [2005-12-18 23:10 UTC] 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 
 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-19 00:46 UTC] helly@php.net
Nothing to do here: Use debug_backtrace()
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Sep 08 18:00:01 2025 UTC