Re: [PHP] Caller's __LINE__

2001-02-28 Thread CC Zona

In article 97ifmk$p85$[EMAIL PROTECTED],
 [EMAIL PROTECTED] ("elias") wrote:

   function debuginfo($msg)
  {
   echo"bthe message is $msg, at line" . __LINE__ . " /bbr";
  }
 
 in my code:
  line 1
  line 2
  line x: debuginfo("hello!!!");
 
 is there is anyway to show the caller's line number? in this case 'x' ?

Pass __LINE__ to the function as one of its arguments:

 function debuginfo($msg, __LINE__)
  {
   echo"bthe message is $msg, at line" . __LINE__ . " /bbr";
  }

-- 
CC

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Caller's __LINE__

2001-02-28 Thread Neil Kimber

Better still - use the set_error_handler() to define an error handler that
will output your debug statement and create your dbug message using
trigger_error(). Your registered error_handler will automatically receive
line number, file name and some other useful parameters.


-Original Message-
From: CC Zona [mailto:[EMAIL PROTECTED]]
Sent: 28 February 2001 09:37
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Caller's __LINE__


In article 97ifmk$p85$[EMAIL PROTECTED],
 [EMAIL PROTECTED] ("elias") wrote:

   function debuginfo($msg)
  {
   echo"bthe message is $msg, at line" . __LINE__ . " /bbr";
  }

 in my code:
  line 1
  line 2
  line x: debuginfo("hello!!!");

 is there is anyway to show the caller's line number? in this case 'x' ?

Pass __LINE__ to the function as one of its arguments:

 function debuginfo($msg, __LINE__)
  {
   echo"bthe message is $msg, at line" . __LINE__ . " /bbr";
  }

--
CC

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Caller's __LINE__

2001-02-28 Thread Christian Dechery


Pass __LINE__ to the function as one of its arguments:

  function debuginfo($msg, __LINE__)
   {
echo"bthe message is $msg, at line" . __LINE__ . " /bbr";
   }

that won't work since __LINE__ returns the exact line where it's used... so 
it will always show the line of the function header...

. Christian Dechery (lemming)
. http://www.tanamesa.com.br
. Gaita-L Owner / Web Developer


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Caller's __LINE__

2001-02-28 Thread Joao Prado Maia


On Wed, 28 Feb 2001, Christian Dechery wrote:


 Pass __LINE__ to the function as one of its arguments:
 
   function debuginfo($msg, __LINE__)
{
 echo"bthe message is $msg, at line" . __LINE__ . " /bbr";
}

 that won't work since __LINE__ returns the exact line where it's used... so
 it will always show the line of the function header...
 
 . Christian Dechery (lemming)
 . http://www.tanamesa.com.br
 . Gaita-L Owner / Web Developer


Okay, simple enough.

Pass __LINE__ as one of its arguments and just use a real variable name on
the function declaration.

function debuginfo($msg, $line_num)
{
  echo"bthe message is $msg, at line $line_num /bbr";
}

debuginfo($msg, __LINE__);

This will probably result in a line number that is one integer bigger than
what you want. For instance the error happened on line 40 and you are
actually calling this function on line 42. You can then just substract 2
from that and you will get the real line number. It's ugly, but works (or
should anyway ;).

Regards,
Joao

--
Joo Prado Maia [EMAIL PROTECTED]
http://phpbrasil.com - php com um jeitinho brasileiro
--
Contribua com o projeto de traduo do manual online do PHP
http://phpbrasil.com/traducao.php
--


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]