# RFC - MACRO

- Thread: https://externals.io/message/51116
- Original archive: https://news-web.php.net/php.internals/51116
- Started by Mathias Grimm on 2010-12-22T17:11:37+00:00
- Messages: 14
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #51116 — Mathias Grimm — 2010-12-22T17:11:37+00:00

URL: https://externals.io/message/51116#51116

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.

---

## #51117 — Mathias Grimm — 2010-12-22T17:17:36+00:00

URL: https://externals.io/message/51116#51117 · In reply to: #51116

<?php
MACRO('TE','throw new Excpeption();');

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



On Wed, Dec 22, 2010 at 3:11 PM, Mathias Grimm <mathiasgrimm@gmail.com>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.

---

## #51118 — Sebastian Bergmann — 2010-12-22T17:27:20+00:00

URL: https://externals.io/message/51116#51118 · In reply to: #51116

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/

---

## #51120 — Stas Malyshev — 2010-12-22T19:43:27+00:00

URL: https://externals.io/message/51116#51120 · In reply to: #51116

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

---

## #51121 — Mathias Grimm — 2010-12-22T19:55:09+00:00

URL: https://externals.io/message/51116#51121 · In reply to: #51120

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.
> > […]
>
> 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

---

## #51122 — Scott MacVicar — 2010-12-22T21:08:44+00:00

URL: https://externals.io/message/51116#51122 · In reply to: #51121

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



> 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:
> 
> > […]

---

## #51123 — Mathias Grimm — 2010-12-22T21:38:11+00:00

URL: https://externals.io/message/51116#51123 · In reply to: #51122

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();
}




> 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
>
> 
>
> > […]
> get
> > […]

---

## #51125 — Sebastian Bergmann — 2010-12-22T22:14:25+00:00

URL: https://externals.io/message/51116#51125 · In reply to: #51120

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/

---

## #51126 — Gwynne Raskind — 2010-12-22T22:28:09+00:00

URL: https://externals.io/message/51116#51126 · In reply to: #51123

> 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?

> 
> > […]

-- Gwynne

---

## #51131 — Andi Gutmans — 2010-12-23T08:06:42+00:00

URL: https://externals.io/message/51116#51131 · In reply to: #51116

> -----Original Message-----
> From: Mathias Grimm [mailto:mathiasgrimm@gmail.com]
> 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

---

## #51132 — nicobn@gmail.com — 2010-12-25T00:28:21+00:00

URL: https://externals.io/message/51116#51132 · In reply to: #51116

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 <mathiasgrimm@gmail.com>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)

---

## #51133 — Mathias Grimm — 2010-12-25T14:14:54+00:00

URL: https://externals.io/message/51116#51133 · In reply to: #51132

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 <mathiasgrimm@gmail.com>wrote:
>
> > […]
>
>
>
> --
> Nicolas A. Bérard-Nault (nicobn@gmail.com)

---

## #51135 — Matthew Weier O'Phinney — 2010-12-26T15:47:34+00:00

URL: https://externals.io/message/51116#51135 · In reply to: #51133

> 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>
>
> > […]
> mon
> > […]
> rote:
> > […]
>
> --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

---

## #51136 — Sean Coates — 2010-12-26T17:54:17+00:00

URL: https://externals.io/message/51116#51136 · In reply to: #51116

> 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
