SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: macros in PHP

  1. #1
    SitePoint Addict jasongr's Avatar
    Join Date
    Jul 2004
    Location
    usa
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    macros in PHP

    Hello

    I have the following code which repeats numerous times in my applicaion:
    PHP Code:
    $memoryManager->checkMemoryQuota($param1$param2); 
    I would like to be able to define a macro called MEM which will translate to the above code.
    So I will be able to write code like so:
    PHP Code:
    MEM($param1$params); 
    which is much shorter
    Is it possible in PHP?
    It is important to note that function checkMemoryQuota actually takes 3 parameters (the 3rd parameter is optional). I would still like the macro to work without having to define 2 macros

    thanks in advance

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, there is no built-in preprocessor in php, but php is an interpreted language, so if you really need it, you can write it. Macros can seriously degrade code readability, so be aware.

  3. #3
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, it's unfortunate. Like stereofrog said though, it's interpreted, so the speed issue isn't there. A big reason for preprocessing was to get it over with on compile (you compile it on a super-fast (relative to that time) mainframe, and it runs faster on the slow client-PC's).


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •