This is a discussion on ECHO within the PHP General forums, part of the PHP Programming Forums category; ECHO is a language construct but still is there any work around to override it or change its functionality???...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
You could try to manipulate what the echo's output by ob_start(), etc.
Or maybe you could change the standard output? On 12/18/06, Fahad Pervaiz <fahad.pervaiz@gmail.com> wrote: > I have written a framework for internationalization. Now i have incoorperate > it into and existing system that is huge and it will take alot of time to > change ECHO to a function call, so i want to override its implementation so > that i can use it for my own purposes with having to change all the echo > calls > > -- > Regards > Fahad Pervaiz > www.ecommerce-xperts.com > > |
|
|||
|
Manipulating out with Output Control Functions sounds a good idea but it can
become cumbersome. Do you know any good methods to control standard output?? On 12/19/06, Casey Chu <heavyccasey@gmail.com> wrote: > > You could try to manipulate what the echo's output by ob_start(), etc. > Or maybe you could change the standard output? > > On 12/18/06, Fahad Pervaiz <fahad.pervaiz@gmail.com> wrote: > > I have written a framework for internationalization. Now i have > incoorperate > > it into and existing system that is huge and it will take alot of time > to > > change ECHO to a function call, so i want to override its implementation > so > > that i can use it for my own purposes with having to change all the echo > > calls > > > > -- > > Regards > > Fahad Pervaiz > > www.ecommerce-xperts.com > > > > > -- Regards Fahad Pervaiz www.ecommerce-xperts.com |
|
|||
|
Fahad Pervaiz wrote:
> ECHO is a language construct but still is there any work around to override > it or change its functionality??? Nope. You're stuck with how it works now. -- Postgresql & php tutorials http://www.designmagick.com/ |
|
|||
|
>On 12/18/06, Fahad Pervaiz <fahad.pervaiz@gmail.com> wrote: >>I have written a framework for internationalization. Now i have incoorperate >>it into and existing system that is huge and it will take alot of time to >>change ECHO to a function call, so i want to override its implementation so >>that i can use it for my own purposes with having to change all the echo >>calls At 12/18/2006 10:01 PM, Casey Chu wrote: >You could try to manipulate what the echo's output by ob_start(), etc. >Or maybe you could change the standard output? Given the probably unalterable nature of echo, I'd say Casey's suggestion of buffering output and running it through a post-processor is an excellent one. However my first choice would probably be to bite the bullet and globally replace echo with my own function. Once that painful step is taken, you can modify the output methodology to your heart's content. This sounds like an excellent object lesson in the separation of logic from markup. If you design your applications to first figure out what to output and then to output it as one or more solid lumps, you can more easily tweak the logic or the markup or the output method without messing with the others. It can be hard medicine to swallow the first time, but it will make you a leaner & cleaner coder. Regards, Paul |
|
|||
|
Fahad Pervaiz wrote:
> ECHO is a language construct but still is there any work around to override > it or change its functionality??? if your willing to hack the php source then you can pretty much do whatever you want; that said there is no mechanism for overriding echo or any other language construct in the std php... there is runkit (http://php.net/runkit) but that doesn't seem to offer language construct overriding based on a quick glance. > |
|
|||
|
You could use the PHP Compiler: http://phpcompiler.org/ and do a
preprocessor as I did: http://www.satyam.com.ar/pht/. PHC is capable of compiling a PHP source and return a modified PHP source. It is easy to make a plugin for any such modifications, there is a class which gets instantiated after parsing and makes a full tree traversal with a method defined for each node type so you simply inherit from the method for your particular tree node and make any modifications you want to it. For PHC echo is not a language construct, you would have to override the "method invocation" method, check whether the function name is "echo" (print is translated to echo) and then do your changes. One of the tutorials shows you how to do this: http://phpcompiler.org/doc/tutorial2.html Satyam ----- Original Message ----- From: "Fahad Pervaiz" <fahad.pervaiz@gmail.com> To: <php-general@lists.php.net> Sent: Tuesday, December 19, 2006 6:46 AM Subject: [php] Re: ECHO >I have written a framework for internationalization. Now i have >incoorperate > it into and existing system that is huge and it will take alot of time to > change ECHO to a function call, so i want to override its implementation > so > that i can use it for my own purposes with having to change all the echo > calls > > -- > Regards > Fahad Pervaiz > www.ecommerce-xperts.com > |
|
|||
|
Thank you Satyam for you help! i think this is the rite solution
On 12/19/06, Satyam <Satyam@satyam.com.ar> wrote: > > You could use the PHP Compiler: http://phpcompiler.org/ and do a > preprocessor as I did: http://www.satyam.com.ar/pht/. > > PHC is capable of compiling a PHP source and return a modified PHP source. > It is easy to make a plugin for any such modifications, there is a class > which gets instantiated after parsing and makes a full tree traversal with > a > method defined for each node type so you simply inherit from the method > for > your particular tree node and make any modifications you want to it. > > For PHC echo is not a language construct, you would have to override the > "method invocation" method, check whether the function name is "echo" > is translated to echo) and then do your changes. One of the tutorials > shows you how to do this: http://phpcompiler.org/doc/tutorial2.html > > Satyam > > > ----- Original Message ----- > From: "Fahad Pervaiz" <fahad.pervaiz@gmail.com> > To: <php-general@lists.php.net> > Sent: Tuesday, December 19, 2006 6:46 AM > Subject: [php] Re: ECHO > > > >I have written a framework for internationalization. Now i have > >incoorperate > > it into and existing system that is huge and it will take alot of time > to > > change ECHO to a function call, so i want to override its implementation > > so > > that i can use it for my own purposes with having to change all the echo > > calls > > > > -- > > Regards > > Fahad Pervaiz > > www.ecommerce-xperts.com > > > > -- Regards Fahad Pervaiz www.ecommerce-xperts.com |