Re: [SMARTY-DEV] Error reporting info in compiled templates

[email protected] (Robert Amos)
Newsgroups php.smarty.dev
Message-ID <[email protected]>
Hi,

I'll start off by agreeing that this could be a useful idea, and there
is nothing stopping you from extending the existing Smarty class and
declaring your own trigger_error method.

Using debug_backtrace() in the main distribution, aside from being
inaccurate, like you said, would also raise the requirements to
PHP4.3.0 or higher, which is an unreasonable requirement considering
that we support as far back as 4.0.6.

Compiled templates are designed so the output of the template EXACTLY
matches how it looked in the template. This has been discussed many
many times on the mailing lists, and so far (to my knowledge anyway)
we've yet to find a solution that lets us align compiled templates
correctly, especially given how complex the compiled foreach/section
constructs are and that its possible for them to take up to 12 lines
to open the construct.

The name of the template being processed, however, can be found with
$smarty->_current_file inside of functions etc, as the smarty object
is also passed amoungst the arguments, it's slightly more difficult
with modifiers, but not impossible.

That being said, it's possible to implement something to pull out line
numbers in plugins etc using debug_backtrace() in
smarty::trigger_error(), but because of the 4.3 requirement, I can't
see this being implemented in the main distribution.

-bok

On Thu, 26 Aug 2004 16:06:10 +0200, Daniel BODEA <[email protected]> wrote:
> Sure. Our system manages data that is provided in a raw form to designers
> that create as many templates as they wish and have the freedom to include
> any piece of info anywhere and in any template.
> 
> We don't provide the templates with a fixed set of data that they can
> display but rather provide Smarty plug-ins that the designers can use to
> retrieve the data that they want to display and then work with it using
> Smarty modifiers, etc.
> 
> We can have for instance a plug-in named "article" that can be invoked by a
> designer using certain parameters in order to fill in a Smarty variable with
> the contents of a certain article or even a list of articles and further on
> the possibilities are limitless.
> 
> Now lets say this plug-in needs to report an error to the designer so that
> he can know the exact location where the error occurred (template name,
> plug-in name and line number). Except using backtraces or complicated
> compiler plug-ins, I couldn't find any Smarty feature that could help in
> this situation.
> 
> This information should be ideally handled by the trigger_error method so
> that the plug-in system need only call this method with the error message
> but a first step would be to make Smarty aware of the correspondence between
> the compiled templates that it includes and the original designer templates
> because as of now, once a template is compiled, any corresponding line
> numbers or template names are lost.
> 
> If this information were available, the plug-in system could report the
> exact location of the error and the trigger_error method could also evolve
> to report the location in just about any situation.
> 
> Daniel
> 
> 
> 
> ----- Original Message -----
> From: "Monte Ohrt" <[email protected]>
> To: "Daniel BODEA" <[email protected]>
> Cc: <[email protected]>
> Sent: Thursday, August 26, 2004 3:38 PM
> Subject: Re: [SMARTY-DEV] Error reporting info in compiled templates
> 
> > Can you give a specific example of how this would work and what this
> > would accomplish?
> >
> > Thanks
> > Monte
> >
> > Daniel BODEA wrote:
> >
> > >Greetings,
> > >
> > >We are using Smarty in a system that needs a little more than a simple
> > >template engine and the plug-ins system is the one that allows for that.
> We
> > >basically provide plug-ins for data retrieval inside the templates and
> let
> > >designers organize their templates the way they see fit and put in the
> > >content of their choice.
> > >
> > >What I believe is missing from Smarty right now though (that is if I'm
> not
> > >mistaken), is the debugging info inside the compiled templates that we'd
> use
> > >for instance to report exact errors to the designers. A data retrieval
> > >plug-in that needs to report an error to the designer can currently
> either
> > >use Smarty's trigger_error method that doesn't tell the designer much or
> > >play around with backtraces and Smarty private variables to try to figure
> > >out the template name, the line number and the plug-in name that the
> > >designer needs to track down the problem, and all this time hoping that
> you
> > >don't stumble upon PHP bugs in backtraces and the like. Needless to say
> this
> > >solution is neither scalable nor does it guarantee consistency with
> future
> > >versions of Smarty.
> > >
> > >The solution would be to track debug info in compiled templates either as
> > >PHP statements that fill in variables or as PHP comments with special
> > >prefixes that don't add any more processing weight to the templates and
> can
> > >be easily searched for in case error reporting is needed.
> > >
> > >This is just the incentive of the idea but I'd first like to know if such
> a
> > >system already exists or if anyone is already working on something
> related
> > >and also if the project's coordinators would be interested in such a
> thing.
> > >
> > >Daniel
> > >
> > >
> > >
> >
> >
> 
> --
> Smarty Development Mailing List (http://smarty.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.