FAQ
I want to request a C/C++ feature that i think is good.

MACRO

<?php
MACRO('PF','private function _');
MACRO('SCOPE_CLASS','class MyProject_');

class UseMacro
{
PF preSave($object)
{
//...
}

}

SCOPE_CLASS Internal
{

}

I don know if there is a RFC for this feature.

Search Discussions

  • Mathias Grimm at Dec 22, 2010 at 5:17 pm
    <?php
    MACRO('TE','throw new Excpeption();');

    function test($var) {
    if ($var < 0) {
    TE
    }
    }


    On Wed, Dec 22, 2010 at 3:11 PM, Mathias Grimm wrote:

    I want to request a C/C++ feature that i think is good.

    MACRO

    <?php
    MACRO('PF','private function _');
    MACRO('SCOPE_CLASS','class MyProject_');

    class UseMacro
    {
    PF preSave($object)
    {
    //...
    }

    }

    SCOPE_CLASS Internal
    {

    }

    I don know if there is a RFC for this feature.
  • Sebastian Bergmann at Dec 22, 2010 at 5:27 pm

    Am 22.12.2010 18:11, schrieb Mathias Grimm:
    I want to request a C/C++ feature that i think is good.
    MACRO
    * https://github.com/andreiz/prep (extension for the PHP interpreter)
    * https://github.com/theseer/preprocessor (userland implementation)

    --
    Sebastian Bergmann Co-Founder and Principal Consultant
    http://sebastian-bergmann.de/ http://thePHP.cc/
  • Stas Malyshev at Dec 22, 2010 at 7:43 pm
    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
  • Mathias Grimm at Dec 22, 2010 at 7:55 pm
    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 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
  • Scott MacVicar at Dec 22, 2010 at 9:08 pm
    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 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 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
  • Mathias Grimm at Dec 22, 2010 at 9:38 pm
    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:

    $method = $_GET['m'];
    $control = $_GET['c'];

    $c = new $control;
    $c->$method();

    like a macro..

    program is make thing dynamic.

    while($object = $iterator->next()) {

    }

    macro("ITER","while($object = $iterator->next())")

    ITER($iterator) {
    $object->save();
    }

    On Wed, Dec 22, 2010 at 7:08 PM, Scott MacVicar 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 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
  • James Butler at Dec 22, 2010 at 9:47 pm

    -----Original Message-----
    From: Mathias Grimm
    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:

    $method = $_GET['m'];
    $control = $_GET['c'];

    $c = new $control;
    $c->$method();

    like a macro..

    program is make thing dynamic.

    while($object = $iterator->next()) {

    }

    macro("ITER","while($object = $iterator->next())")

    ITER($iterator) {
    $object->save();
    }

    From a userland perspective this looks very un-PHP and potentially hugely confusing when new people come across it. Also what scope would these things exist at? global scope macro's sound like evil waiting to happen
    What you are doing looks to be just slightly re-inventing the wheel for very little gain. If you are copy and pasting code 'DRY violation' then you probably need to rethink your code and/or make a new class/function of some sort.
    Unless i'm missing something?

    On Wed, Dec 22, 2010 at 7:08 PM, Scott MacVicar 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 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
  • Mathias Grimm at Dec 23, 2010 at 12:48 am
    On Wed, Dec 22, 2010 at 7:47 PM, James Butler wrote:
    "What you are doing looks to be just slightly re-inventing the wheel for
    very little gain. If you are copy and pasting code 'DRY violation' then you
    probably need to rethink your code and/or make a new class/function of some
    sort.
    Unless i'm missing something?"

    There are some projects (like one that im working) have more than 3.000.000
    lines of O.O php coding.
    Isn't it a cut and paste, but are some code that everywhere i need to
    repeat, for exemplo (php4 yet)

    $obError = $object->fetch($params,$transaction);
    if ($obError->hasError()) { return $obError;) // this is repeated everey
    processing... every method call.. like try catch..

    i could replace with a macro:
    MACRO("HND_ERR","if ($obError->hasError()) { return $obError;)")
    $obError = $object->fetch($params,$transaction);
    HND_ERR
  • Gustavo Lopes at Dec 23, 2010 at 12:57 am

    On Thu, 23 Dec 2010 00:48:44 -0000, Mathias Grimm wrote:

    On Wed, Dec 22, 2010 at 7:47 PM, James Butler
    wrote:

    i could replace with a macro:
    MACRO("HND_ERR","if ($obError->hasError()) { return $obError;)")
    $obError = $object->fetch($params,$transaction);
    HND_ERR
    So, not only do you want macros, you want to write flow control macros...

    http://blogs.msdn.com/b/oldnewthing/archive/2005/01/06/347666.aspx

    --
    Gustavo Lopes
  • Mathias Grimm at Dec 23, 2010 at 1:07 am
    there are particupal points to aply a macro, like $_GLOBALS,like eval...
    particular reasons.

    zend engine and php internals are macro-oriented programing...

    you can define a pattern(prefix,sufix,etc...) to ensure the purpose of
    macros, avoiding doubts..

    RET_IF_ERR is a clean macro..

    MACRO_1 is a very perl-read-only-macro..

    doValidations() is a clean method.

    process() is a poor description method... and so on..



    On Wed, Dec 22, 2010 at 10:57 PM, Gustavo Lopes wrote:

    On Thu, 23 Dec 2010 00:48:44 -0000, Mathias Grimm wrote:

    On Wed, Dec 22, 2010 at 7:47 PM, James Butler <
    james.butler@edigitalresearch.com> wrote:

    i could replace with a macro:
    MACRO("HND_ERR","if ($obError->hasError()) { return $obError;)")
    $obError = $object->fetch($params,$transaction);
    HND_ERR
    So, not only do you want macros, you want to write flow control macros...

    http://blogs.msdn.com/b/oldnewthing/archive/2005/01/06/347666.aspx

    --
    Gustavo Lopes


    --
    PHP Internals - PHP Runtime Development Mailing List
    To unsubscribe, visit: http://www.php.net/unsub.php
  • Stas Malyshev at Dec 23, 2010 at 1:17 am
    Hi!
    zend engine and php internals are macro-oriented programing...
    Zend Engine and PHP internals is not the code you deal with every day.
    Especially not the PHP code you deal with.
    PHP is supposed to be simple to read and understand, and heavy use of
    macros (like ZE code does) would certainly make such code very hard to
    understand for most people. In the guts of the engine, it doesn't matter
    too much, since not many people are supposed to read it anyway. In PHP,
    it does.

    --
    Stanislav Malyshev, Software Architect
    SugarCRM: http://www.sugarcrm.com/
    (408)454-6900 ext. 227
  • Gwynne Raskind at Dec 22, 2010 at 10:28 pm

    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 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 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
  • Sebastian Bergmann at Dec 22, 2010 at 10:14 pm

    Am 22.12.2010 20:43, schrieb Stas Malyshev:
    And then run it through CPP (gcc -Mcpp -E - - < in.php > out.php) and
    get all the macros processed?
    That would be too easy ;-)

    --
    Sebastian Bergmann Co-Founder and Principal Consultant
    http://sebastian-bergmann.de/ http://thePHP.cc/
  • Andi Gutmans at Dec 23, 2010 at 8:06 am

    -----Original Message-----
    From: Mathias Grimm
    Sent: Wednesday, December 22, 2010 9:12 AM
    To: internals@lists.php.net
    Subject: [PHP-DEV] RFC - MACRO

    I want to request a C/C++ feature that i think is good.

    MACRO

    <?php
    MACRO('PF','private function _');
    MACRO('SCOPE_CLASS','class MyProject_');

    class UseMacro
    {
    PF preSave($object)
    {
    //...
    }

    }

    SCOPE_CLASS Internal
    {

    }

    I don know if there is a RFC for this feature.
    Although I am a C developer and use macros I think it'd be horrible to add them to PHP (+ it's been discussed and rejected many times in the past).

    Macros make it very hard for a third party person to read your code + goes directly against the verbosity spirit we've always had in the PHP project. Forget also the fact that it creates a lot of problems with solutions such as debuggers.

    I suggest if it's something you really feel you need then implement it externally to PHP as part of your build and deployment environment. There are a variety of templating/pre-processor solutions out there including the C-compiler tools themselves.

    Andi
  • Nicolas A. Bérard-Nault at Dec 25, 2010 at 12:28 am
    This has been brought up countless times and has always been rejected
    (browse the archives if you aren't convinced).

    Anyhow, I just hope I never have to maintain code you write in this fashion.
    Pre-compilation macros are very out of character in the dynamic languages
    paradigm and I doubt they'd be useful in any case. The examples you gave
    convinced me once and for all that this is a very² bad idea. There's a
    reason why no modern language uses three letters tokens for common
    statements, I'll let you guess what it is.

    Anyhow, merry Christmas.

    P.S.: SCOPE_CLASS ? Have you ever heard of namespaces ?
    On Wed, Dec 22, 2010 at 12:11 PM, Mathias Grimm wrote:

    I want to request a C/C++ feature that i think is good.

    MACRO

    <?php
    MACRO('PF','private function _');
    MACRO('SCOPE_CLASS','class MyProject_');

    class UseMacro
    {
    PF preSave($object)
    {
    //...
    }

    }

    SCOPE_CLASS Internal
    {

    }

    I don know if there is a RFC for this feature.


    --
    Nicolas A. Bérard-Nault (nicobn@gmail.com)
  • Mathias Grimm at Dec 25, 2010 at 2:14 pm
    You never know me.

    php 4 doesnt have namespace, it was just an example.
    zend framework dont use namespecaes yet... and classe names get longer for
    example.

    a think that macros in the framework, not in the user (programmer) space are
    usefull sometimes. as i sad before.. RET_IF_ERR is very clean and anyone can
    understand it.

    as well as framewrok methods need to be understand, some macros will too





    2010/12/24 Nicolas A. Bérard-Nault <nicobn@gmail.com>
    This has been brought up countless times and has always been rejected
    (browse the archives if you aren't convinced).

    Anyhow, I just hope I never have to maintain code you write in this
    fashion. Pre-compilation macros are very out of character in the dynamic
    languages paradigm and I doubt they'd be useful in any case. The examples
    you gave convinced me once and for all that this is a very² bad idea.
    There's a reason why no modern language uses three letters tokens for common
    statements, I'll let you guess what it is.

    Anyhow, merry Christmas.

    P.S.: SCOPE_CLASS ? Have you ever heard of namespaces ?
    On Wed, Dec 22, 2010 at 12:11 PM, Mathias Grimm wrote:

    I want to request a C/C++ feature that i think is good.

    MACRO

    <?php
    MACRO('PF','private function _');
    MACRO('SCOPE_CLASS','class MyProject_');

    class UseMacro
    {
    PF preSave($object)
    {
    //...
    }

    }

    SCOPE_CLASS Internal
    {

    }

    I don know if there is a RFC for this feature.


    --
    Nicolas A. Bérard-Nault (nicobn@gmail.com)
  • Matthew Weier O'Phinney at Dec 26, 2010 at 3:47 pm

    On 2010-12-25, Mathias Grimm wrote:
    php 4 doesnt have namespace, it was just an example.
    zend framework dont use namespecaes yet... and classe names get longer for
    example.
    But that doesn't stop you from using PHP 5.3 and using class aliasing
    already (heck, I do this already, particularly in examples for
    webinars/conference sessions). This accomplishes the same thing (in this
    particular scope), using features already available in the language.
    a think that macros in the framework, not in the user (programmer)
    space are usefull sometimes.
    I'd argue the opposite. Within a framework, you want the code to be as
    readable as possible, so _anybody_ can pick it up and help maintain it.
    That often means a certain level of verbosity, to ensure developers know
    *exactly* what is going on at each and every level of the code.
    as i sad before.. RET_IF_ERR is very clean and anyone can understand
    it.

    as well as framewrok methods need to be understand, some macros will
    too





    2010/12/24 Nicolas A. B=E9rard-Nault <nicobn@gmail.com>
    This has been brought up countless times and has always been rejected
    (browse the archives if you aren't convinced).

    Anyhow, I just hope I never have to maintain code you write in this
    fashion. Pre-compilation macros are very out of character in the dynamic
    languages paradigm and I doubt they'd be useful in any case. The examples
    you gave convinced me once and for all that this is a very=B2 bad idea.
    There's a reason why no modern language uses three letters tokens for com= mon
    statements, I'll let you guess what it is.

    Anyhow, merry Christmas.

    P.S.: SCOPE_CLASS ? Have you ever heard of namespaces ?

    On Wed, Dec 22, 2010 at 12:11 PM, Mathias Grimm <mathiasgrimm@gmail.com>w=
    rote:
    I want to request a C/C++ feature that i think is good.

    MACRO

    <?php
    MACRO('PF','private function _');
    MACRO('SCOPE_CLASS','class MyProject_');

    class UseMacro
    {
    PF preSave($object)
    {
    //...
    }

    }

    SCOPE_CLASS Internal
    {

    }

    I don know if there is a RFC for this feature.


    --
    Nicolas A. B=E9rard-Nault (nicobn@gmail.com)
    --00235445ba821c252204983cbac0--

    --
    Matthew Weier O'Phinney
    Project Lead | matthew@zend.com
    Zend Framework | http://framework.zend.com/
    PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
  • Sean Coates at Dec 26, 2010 at 5:55 pm

    I want to request a C/C++ feature that i think is good.

    MACRO
    FWIW, you could use Prep ( https://github.com/andreiz/prep ) and GPP ( http://en.nothingisreal.com/wiki/GPP ) to accomplish this.

    S

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedDec 22, '10 at 5:11p
activeDec 26, '10 at 5:55p
posts19
users11
websitephp.net

People

Translate

site design / logo © 2022 Grokbase