On Tue, May 7, 2013 at 4:30 PM, Sebastian Krebs <krebs....@gmail.com> wrote:

> 2013/5/7 Bob Weinand <bobw...@hotmail.com>
>
> >
> > Am 7.5.2013 um 22:11 schrieb Stas Malyshev <smalys...@sugarcrm.com>:
> >
> > > Hi!
> > >
> > >> And today we have the problem that we cannot use in any useful manner
> > >> trigger_error in libraries, when we don't know where the error
> > >> originates from. You debug today trigger_error's in libraries with
> > >> putting a debug_print_backtrace behind the trigger_error. I think you
> > >
> > > Why not use a debugger to debug? Debuggers have backtrace tools.
> > >
> > >> (there you can add a backtrace) too, but you have to catch them, if
> > >> not your script will abort; but I only need a notice...)
> > >
> > > If you need additional information in the notice, you can always add it
> > > to the text of the notice.
> > >
> > > --
> > > Stanislav Malyshev, Software Architect
> > > SugarCRM: http://www.sugarcrm.com/
> > > (408)454-6900 ext. 227
> > >
> > > --
> > > PHP Internals - PHP Runtime Development Mailing List
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> > nothing against the debugger, but it'd be something really time saving to
> > see the entry point instantly instead of having to use the debugger
> first...
> >
> > And yes, I can add it to the text (I can even add a function between
> which
> > analyses the backtrace first), but I think we need more useful (= more
> > information) error throwing in PHP?
> >
>
> How do you want to find out, which call _initially_ set the invalid values?
> Is this even (reliable) possible? I've given an example, that it isn't that
> trivial.
> So even if you have the two additional parameters, what will you set there
> (except maybe something like "__LINE__-4", which is as trivial as useless)?
> With this in mind: How do you think the additional parameters _can_ help?
>
> Another example
>
> function foo() {
>   return 0;
> }
>
> function bar($a) {
>   div($a);
> }
>
> function div($a) {
>   if ($a == 0) trigger_error('');
> }
>
> div(bar(foo()));
>
> Which line should the message report now:
>
> - bar() because it calls div()?
> - or foo() because it is the function, that returns the invalid value, that
> is used later? But 0 is maybe a valid return value for foo()?
> - or div(bar(foo()));, but how to find out, that foo() _really_ returned
> the invalid value?
>
> Like in my other example you can report any file and line you want and
> which is maybe/probably involved, but in most if not all cases it doesn't
> prevent you from debugging.
>

PHP wouldn't auto-magically be figuring it out - the person writing the PHP
code would be the one to figure it out.

If you wrote a bigint library and of those three functions the only one you
wrote was div() then presumably you - as the author of that bigint library
- would make it show the line number on which the div() was called. Maybe
bar() and foo() trigger errors as well.. who knows. Just because you have
everything on the same line doesn't mean you can't have multiple errors on
the same line. That's really the business of the end-user using the bigint
lib.

And if you, as a PHP developer, wrote all three functions - foo(), bar()
and div()...  it's up to you which one shows up as being the call that
caused the error. PHP shouldn't be trying to auto-magically figure it out
nor was that my proposal.

It's like...  if someone writes a callback function for preg_replace() the
person who wrote that function is going to be the one who decides what
subpattern - if any - that function is going to look at. I don't know why
anyone would expect PHP to auto-magically figure it out.

Reply via email to