Re: [PEPr] Comment on Internationalisation::Locale_Maketext

From: Date: Tue, 13 Apr 2004 20:45:17 +0000
Subject: Re: [PEPr] Comment on Internationalisation::Locale_Maketext
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-27590@lists.php.net to get a copy of this message
Michael Wallner: > > Despite a few (pedantic) CS issues (I know ;-) ), I wonder > if it is really necessary to create functions on the fly > for each message. What's the idea behind that? It comes from the basic idea that if you want to get grammar right, you may have to do this on a per-message basis (worst-case scenario). And if you want to encapsulate the logic for that very message, you want to put it into its own function. This is explained in the TPJ article. If you need to do something really really complicated in one language, where Bracket Notation would not be suited, you can write the function to encapsulate the logic yourself, for example in an _init() method which could be called from factory() function _init() { $this->set_msg_func('complex_magic_stuff', create_function('&$this,$args', "#... magic code here")); } and later, you could use this as $lh->maketext('complex_magic_stuff', $foo, $bar); Seen from this point of view, Bracket Notation is just a "nice to have" addon to Maketext. (But it is certainly not, Bracket Notation is crucial to Maketext, because it puts the burden of specifying grammatical correctness away from the programmer and onto the translator!) Also, compiling to an anonymous function has the advantage that I can cache that function and then transparently use the same message function many times: $lh->maketext('Hello [_1]', 'Michael'); # compile,cache $lh->maketext('Hello [_1]', 'Jean'); # reuse $lh->maketext('Hello [_1]', 'Hans'); # reuse Neat, not? :-) > ps: extending PEAR is not a requirement This is something I didn't understand about PEAR.php. If I use PEAR::raiseError() with PEAR_ERROR_DIE statically, can the Error be caught at all? And if it cannot, then why use raiseError() at all? I don't see the point. Can someone shed some light on this? By the way, the documentation shows no examples whatsoever on using raiseError() statically. On the same issue, I saw a comment somewhere that trigger_error() may be handled nicely in (future?) PHP. Now, honestly, are the classes PEAR and PEAR_Error really so useful then? Why? Hans

« previous php.pear.dev (#27590) next »