Purple 404
Recognized Expert Contributor
Hi all,
So get_class($this) will return my class name, how do I get the name of the method ?
Thanks Purple..
18 1300 ak1dnar 1,584
Recognized Expert Top Contributor
Try this: - <?php
-
class _Class{
-
function myfunc1(){
-
return(true);
-
}
-
function myfunc2(){
-
return(true);
-
}
-
-
}
-
$methods = get_class_methods(new _Class());
-
print_r ($methods);
-
//or
-
print "<br>";
-
print $methods[0];
-
print "<br>";
-
print $methods[1];
-
?>
EDIT: Now Only I read the things on title :D
Is this solved your problem?
Purple 404
Recognized Expert Contributor
Thanks for the response ajaxrand but it didn't..
Using your code:
[PHP]<?php
class _Class{
function myfunc1(){
do_function_that_errors()
or die("error in class ". get_class(). " method ". Method name here() );
return(true);
}
function myfunc2(){
return(true);
}
}
$methods = get_class_methods(new _Class());
print_r ($methods);
//or
print "<br>";
print $methods[0];
print "<br>";
print $methods[1];
?>[/PHP]
Regards Purple
ak1dnar 1,584
Recognized Expert Top Contributor
Hey Purple, What you are trying to do?
Purple 404
Recognized Expert Contributor
Hi Ajaxrand,
I am reworking the diagnostics and logging component of a site before putting a whole new chunk of functionality live.. Cause its a live site I want to be able to trap and kill any bugs as fast as possible - to that end, the logging function currently catches some basic info about who, when, which machine and maybe what the user was doing when it all went wrong.
So I am looking at other ways to capture more specific info on where the code is upto at exception points, hence why I would like to know if there is an function which will return the method / function within a class that is being executed.
Hope that helps
Regards Purple
Purple 404
Recognized Expert Contributor
Thanks pbmods,
thats the answer I was looking for, I think I need to spend time practising to be a magician - those magic methods and constants get me everytime :)
Reviewing the other constants, thats really cool, will help loads in trapping exceptions - I think you should write an article on this stuff...
Purple
pbmods 5,821
Recognized Expert Expert
Heya, Purple.
Noted.
All I have to do first is finish my current articles on PHPDocumenter, Mass Virtual Hosting on Localhost and print_r() for JavaScript.
ak1dnar 1,584
Recognized Expert Top Contributor
Yeah That's really cool pb!
Hey Purple, make sure to asked the questions with sufficient info! (just kidding)
Any probs here? - <?php
-
class userLogin
-
{
-
function userLogin()
-
{
-
$this->dbName = 'purple';
-
}
-
function matchThem($thisName)
-
{
-
if(!($thisName == $this->dbName)) die('ERROR IN:'.__METHOD__);
-
echo 'Matching Record Found';
-
}
-
}
-
$newUser = new userLogin;
-
$newUser->matchThem('purple1');
-
?>
Purple 404
Recognized Expert Contributor
pbmods,
whatcha waiting for :)
Purple.
ak1dnar 1,584
Recognized Expert Top Contributor - do_function_that_errors() or die(WHAT EVER);
guys, Is this possible?
Purple 404
Recognized Expert Contributor
Hi Ajaxrand,
this is a snip of what I have
[PHP]class my_class{
class variables, contructor and some other functions
//*
//* exec_sql - execute a sql statement
//*
function exec_sql() {
if ($this->sql == null) die($this->error_logger(__method__,__line__));
$result_obj = odbc_exec($this->sql_conn,$this->sql) or die($this->error_logger(__method__,__line__));
return $result_obj;
}
//*
//* error loggging method
//*
function error_logger($method, $line) {
echo "errror in call from ".$method." on line ".$line;
// will write to diagnostic area and log
}
}[/PHP]
about the same in code terms...
Purple
pbmods 5,821
Recognized Expert Expert
Heya, Ajaxrand.
The reason why that works with mysql_connect(), et al is because those functions return false when they fail to connect.
You'll want to do this instead (PHP 5): -
try
-
{
-
do_function_that_errors();
-
}
-
catch( Exception $e )
-
{
-
$msg = $e->getMessage();
-
-
if( empty($msg) )
-
{
-
exit('P0wN3d!');
-
}
-
exit($msg);
-
}
-
PS. The Javascript article is almost finished; it just needs some more testers! http://www.thescripts.com/forum/thread668433.html Purple 404
Recognized Expert Contributor
Hi all,
Just reading debug_backtrace() function, will give me even more info on error - anyone used it ? comments, thoughts ?
Purple
Purple 404
Recognized Expert Contributor
I have just tried the debug_backtrace() function and I have found a new best friend - debugging from hell to heaven..
Now why didn't one of you point it out to me before !! All that wasted time..
If you haven't tried it give it a go - fantastic..
Just need to rewrite my error logger (again)
Purple
Purple 404
Recognized Expert Contributor
LOL - I am learning so much today
even found an urban dictionary..
Purple
pbmods 5,821
Recognized Expert Expert
Heya, Purple.
Thanks for mentioning debug_backtrace(). I don't know how I missed it.
Atli 5,058
Recognized Expert Expert
While were talking about backtrace...
If your using exceptions you can do: -
try{
-
// Do stuff
-
}
-
catch(Exception $ex) {
-
echo "<pre>". $ex->getTraceAsString() ."</pre>";
-
}
-
Very helpful when debugging.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: CJ |
last post by:
Why won't this work?
I am passing the name of the form (I have two that use this validation
script) but I keep getting an error.
Error reads: "document.which_form.name is null or not an object"
...
|
by: Martin |
last post by:
I'd like to be able to get the name of an object instance from within
a call to a method of that same object. Is this at all possible?
The example below works by passing in the name of the object...
|
by: William H. Burling |
last post by:
i have a nest of vb.vanilla collections.
CollectionofHotelData.item("great Pequot").item("2000").item(22)
The above works. I wrote the code that constructs the nested collections
and i can...
|
by: clr |
last post by:
I like to stamp trace logs with the name of the executing Class and Method.
I can get the Class Name using GetType.Name and I can get a list of every
Method in the class using...
|
by: Bob Day |
last post by:
Using vs2003, vb.net
I start a thread, giving it a name before start. Code snippet:
'give each thread a unique name (for later identification)
Trunk_Thread.Name = "Trunk_0_Thread"
' allow...
|
by: AngryGerbil |
last post by:
hey,
How do I acquire MethodInfo WITHOUT hardcoding method name as a
string?!??!The fact I have to use xxx.Gettype.GetMethod("MyMethod",
xxx) is making me want to drive an ice pick into my eye!
I...
|
by: weston |
last post by:
I've got a piece of code where, for all the world, it looks like this
fails in IE 6:
hometab = document.getElementById('hometab');
but this succeeds:
hometabemt =...
|
by: Alexander Walker |
last post by:
Hello
I would like to write a method that allows me to pass a reference to an instance
of a class, the name of a property of that class and a value to set that
property to, the method would then...
|
by: |
last post by:
Is it possible to get the name of the method that the code is currently
executing in so that I can pass it to another method? For example, in void
method1() I will call void method5(). In method5...
|
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= |
last post by:
I have a C# logging assembly with a static constructor and methods that is
called from another C# Assembly that is used as a COM interface for a VB6
Application. Ideally I need to build a file...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |