php macro?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alanchinese
Forum Newbie
Posts: 11
Joined: Fri Jun 11, 2004 4:53 pm

php macro?

Post by alanchinese »

hi, in my php program i need to do the following repeatly:

$newObject = new COM("comObject") or die("comObject could not be started");

is there a way for me to create a macro so that i only need to do the following:
$newObject = $macroComObject;

thankx a lot.
from alan.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you could make a function that performs it..

Code: Select all

<?php

function newObject($name)
{
  return new COM($name) or die("{$name} could not be started");
}

$newObject = newObject("comObject");

?>
Last edited by feyd on Fri Jun 25, 2004 2:08 pm, edited 1 time in total.
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

Code: Select all

<?php
function macroComObject(){
   return  new COM("comObject") or die("comObject could not be started"); 
}

$newObject = macroComObject(); 

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

heh
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post by magicrobotmonkey »

heh is right
alanchinese
Forum Newbie
Posts: 11
Joined: Fri Jun 11, 2004 4:53 pm

Post by alanchinese »

returning from a function is a good idea, but this is not what I wanted.

i want "macro" to replace some repeated strings + (part of ) statements combination, just like what C provided.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

there is no macro functionality like that in php that I'm aware of.

you could potentially use eval to create something like it.. but this is a hack at best...
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

alanchinese wrote: i want "macro" to replace some repeated strings + (part of ) statements combination, just like what C provided.
doesn't your editor support macros? 8O
Post Reply