Re: RFC - MACRO
| From: | Gwynne Raskind | Date: | Wed, 22 Dec 2010 22:28:09 +0000 |
| Subject: | Re: RFC - MACRO | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51126@lists.php.net to get a copy of this message | ||
On Dec 22, 2010, at 4:38 PM, Mathias Grimm wrote:
> People always will want more, but some features are nice.
> for C/C++ programmers, macro is on of the best things to make thing work
> every where.
>
> its possible to create a IDE macro, but the native php feature will be good.
> template engines can de wrap this functionality too.
> is just like a variable:
I've long wished for preprocessing in PHP. It would be semi-trivial to plug in libcpp from GCC
or llvm's preprocessing library, if licensing weren't an issue. If it is, then a
reasonable homegrown implementation of C's preprocessor semantics, or at least a subset of
them, isn't that difficult.
Piping through cpp has two major problems:
1) It's an extra runtime step. Slower, more error-prone, not always an option (shared hosting
anyone?).
2) cpp doesn't understand # comments, single-quoted strings, heredocs, etc. Many PHP scripts
therefore produce annoying/confusing errors.
Some issues with PHP-native preprocessing:
- Are eval() strings subject to it? At what stage, outer script processing or the eval string?
- #include/#import versus include()/require() - confusing
- Does preprocessing take place outside whatever PHP tags are active?
> On Wed, Dec 22, 2010 at 7:08 PM, Scott MacVicar <scott@macvicar.net> wrote:
>> I really dislike this, what about resolving orders, then people will want
>> undef, then ifdef with conditions.
>>
>> The language doesn't need to introduce anything that makes it more complex
>> to use.
>>
>> - Scott
>>
>> On 22 Dec 2010, at 11:55, Mathias Grimm <mathiasgrimm@gmail.com> wrote:
>>> I Just want a simple replace-on-the-air to avoid spend time writing more.
>>>
>>>
>>> On Wed, Dec 22, 2010 at 5:43 PM, Stas Malyshev <smalyshev@sugarcrm.com
>>> wrote:
>>>
>>>> Hi!
>>>>
>>>>
>>>> I want to request a C/C++ feature that i think is good.
>>>>>
>>>>> MACRO
>>>>>
>>>>
>>>> You know that you could write:
>>>> <?php
>>>> #define PF private function
>>>> #define SCOPE_CLASS(x) class MyProject_ ## x
>>>>
>>>>
>>>> class UseMacro
>>>> {
>>>> PF preSave($object)
>>>> {
>>>> //...
>>>> }
>>>>
>>>> }
>>>>
>>>> SCOPE_CLASS(Internal)
>>>> {
>>>>
>>>> }
>>>>
>>>> And then run it through CPP (gcc -Mcpp -E - - < in.php > out.php) and
>> get
>>>> all the macros processed?
>>>> --
>>>> Stanislav Malyshev, Software Architect
>>>> SugarCRM: http://www.sugarcrm.com/
>>>> (408)454-6900 ext. 227
>>>>
>>
-- Gwynne