Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67355 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2788 invoked from network); 7 May 2013 20:02:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 May 2013 20:02:41 -0000 Authentication-Results: pb1.pair.com header.from=zelnaga@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=zelnaga@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: zelnaga@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wg0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:40500] helo=mail-wg0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/16-06696-FDD59815 for ; Tue, 07 May 2013 16:02:40 -0400 Received: by mail-wg0-f49.google.com with SMTP id j13so1034172wgh.28 for ; Tue, 07 May 2013 13:02:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=LJ9yu2IaDWl4Uw7LHEgMnAFJf3/tVK92wVzuCCPebpw=; b=pLZt+uXFCxwWhR/sgq2FQbif/h3dHdm7sd0OqcGIKqcvyuna296m6ijeNsQqDR6TZg sqkNOZL8m4ZBvBZzlyq0T5smZvRzgZ0xSVcB/kIJGU/p2kQ2x/0565iXgnrrexD+RWQ2 bW2hcWpCU+wuvqWA3fFE7321g/Br9cqsHQSXRjkMPine0vSgj51Cg4nv3I/pcSBvdPJE 9w1ojePlFXW3AlQBvkzEM+GEO6OMhgSsabi16oRU0ilxadBsDy0e75yzUBT2KQ9HSsNe WuI6y3Pu6bBm/RWSVppK0LTGgdP1RjLTH18s7874tH/Bbhn0MT93mLdFA6I/s7YVe2E2 YIvQ== MIME-Version: 1.0 X-Received: by 10.194.92.176 with SMTP id cn16mr5776122wjb.51.1367956957432; Tue, 07 May 2013 13:02:37 -0700 (PDT) Received: by 10.194.77.48 with HTTP; Tue, 7 May 2013 13:02:37 -0700 (PDT) In-Reply-To: References: Date: Tue, 7 May 2013 15:02:37 -0500 Message-ID: To: Sebastian Krebs Cc: Bob Weinand , PHP List Developers Mailing Content-Type: multipart/alternative; boundary=047d7beb986e8412aa04dc264ce0 Subject: Re: [PHP-DEV] idea: letting the line number and file name be set via user_error From: zelnaga@gmail.com (Thomas Anderson) --047d7beb986e8412aa04dc264ce0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Tue, May 7, 2013 at 2:49 PM, Sebastian Krebs wrote= : > 2013/5/7 Bob Weinand > > > > > Am 7.5.2013 um 21:07 schrieb Sebastian Krebs : > > > > > > > > > > 2013/5/7 Bob Weinand > > > >> > >> Am 7.5.2013 um 18:25 schrieb Ferenc Kovacs : > >> > >> > On Tue, May 7, 2013 at 6:09 PM, Thomas Anderson > >> wrote: > >> > > >> >> If you do user_error('whatever') it'll show, as the line number for > >> that > >> >> error, the line number on which that user_error() call is made. It= 'd > >> be > >> >> nice if you could control the line number and file name that was > >> displayed. > >> >> eg. > >> >> > >> >> >> >> function test() { > >> >> user_error('whatever'); > >> >> } > >> >> > >> >> test(); > >> >> ?> > >> >> > >> >> That'll say "Notice: whatever in ... on line 4" (ie. the line that > the > >> >> user_error is on) instead of "Notice: whatever in ... on line 7" (i= e. > >> the > >> >> line that the call to the test() function is made). > >> >> > >> >> If the displayed line numbers could be controlled by user_error the= n > >> >> debug_backtrace could be used to get the desired line number / file > >> name to > >> >> display. > >> >> > >> > > >> > line 3, but I suppose that is just a typo on your part. > >> > the default error handler reports the line when the actual error is > >> > generated and it also provides a backtrace so you can see the > callchain > >> for > >> > the execution. > >> > I think that this is a sensible default, and allowing to fake that > from > >> the > >> > userland would make the debugging of the problems harder, as many/mo= st > >> > people would look up the file:line number and would be surprised tha= t > >> there > >> > is no E_USER_* thrown there. > >> > Additionally I'm not sure how/where would you get your fake line > >> numbers. > >> > You would either need to hardcode those in your application and make > >> sure > >> > that the reference and the actual content of your file is in sync (y= ou > >> will > >> > screw yourself over sooner or later) or you would use __LINE__ + > offset > >> > which is still error prone.. > >> > > >> > I didn't like this proposal. > >> > > >> > -- > >> > Ferenc Kov=E1cs > >> > @Tyr43l - http://tyrael.hu > >> > >> 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. > > > > > > Still don't get it: > > > > if ($errorCond) { > > trigger_error(); > > } > > > > The error orginates from at most one line before... > > > > > > And $errorCond may have some long complicated preprocessing by internal > > functions of the framework I don't want to know about, so that I cannot > > imagine instantly what's going on? > > > > You debug today trigger_error's in libraries with putting a > >> debug_print_backtrace behind the trigger_error. > >> > > > > I use a debugger :X > > > > > > I don't know why, but I find it more comfortable to debug with gdb than > > with xDebug. With gdb it's only setting a break into the trigger_error > > function and then use zbacktrace... But for debugging on some productio= n > > system because only there something goes wrong for some reason, I > wouldn't > > want to install xDebug (which will be loaded at every request...). > > > > Yes, "debugging by logs" is hard and debugging on a production is "not > ideal", thus you should try to reproduce the problem on your development > machine. Here you can have any extension you like :) > > > > But to some my concerns up: I am unsure, if it is useful to let the error > message lie to you. It should tell you, where it appears, not where some > reason occured (or not), that might cause the call, that contains the lin= e, > where the error occurs. > > > function foo1($a) { > foo2($a); > } > > function foo2($a) { > foo3($a); > } > > function foo3($a) { > foo4($a < 0 ? 0 : $a); > } > > function foo4($a) { > foo5($a); > } > > function foo5($a) { > if ($a =3D=3D 0) trigger_error('Foo'); > } > > foo1(42); // OK > foo1(0); // Error > foo1(-42); // Error, but the wrong value now comes from foo3() > > > So now which line should the error report? Note, that in foo3 is a > condition, which makes it non-trivial to find out, where the wrong value > were injected the first time. > I'd say that's up to the developer. If foo2-5 aren't intended to be publicly accessible to the initial foo1() call. I'm not proposing that the behavior of existing trigger_error() calls should be modified - rather that new parameters be added or something whereby the line number / file name can be specified. If they're not then PHP should show the line and file on which the trigger_error() call was made. --047d7beb986e8412aa04dc264ce0--