php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #46017 Make C-Like Macros for PHP
Submitted: 2008-09-07 13:50 UTC Modified: 2009-12-27 13:17 UTC
Votes:35
Avg. Score:4.6 ± 0.7
Reproduced:31 of 31 (100.0%)
Same Version:16 (51.6%)
Same OS:10 (32.3%)
From: ben at umingo dot de Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.2.6 OS: Windows
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-09-07 13:50 UTC] ben at umingo dot de
Description:
------------
Hello people, i want to ask you for macros for PHP. 
Main purpose is to switch projects between testing, developing and production state without performance penalties.

All these runtime if's could be skipped and that is jsut one example. 

It just gives you some more options
I really miss macros from C and C++ days ...

another useful example is for logging, 
I dont want to write a __LINE__ and __FILE__ everytime i log something. 
It would be much nicer to use a macro that will expand my logfunction with these parameters before compiling ... you know what i mean

The bigger the project the bigger the effect of compiling times and execution times ... This could really be a speedup and at all nobody is forced to use macros.

(in case php scripts are cached and precompiled)




Reproduce code:
---------------
//projectstate 
//0 testing
//1 developing
//2 production
#define projectstate = 0

//some code ...

#if projectstate == 0
 //write some log, some output or whatever
}
#endif

//some other code

Expected result:
----------------
With macros, the code would be just 

//some code ...
//some other code...

Actual result:
--------------
Without macros, the code would be 

//some code
//an if-querry for projectstate
//some hundred lines of code to parse and evaluate
//endif
//some other code

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-12-27 08:01 UTC] john2496 at gmail dot com
I agree, php needs macros. There is no way to represent a set of function calls that need to be made within the local scope.

I'd need to use the following line of code every time I wanted to merge variables to the local scope.

extract(array_merge_recursive(get_defined_vars(), $anArray)));

instead of..

extract_recursive($anArray);
 [2009-12-27 13:17 UTC] pajoye@php.net
See the previous reports for the (good) reasons not to implement macros.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 13:01:30 2024 UTC