Skip to main content
Inspiring
January 31, 2008
Question

Working with an API (PHP) question

  • January 31, 2008
  • 3 replies
  • 234 views
I am building a mini-app using an API into another back-end system. To
extract data from this system, I can use PHP lines like this -

$stats = $q->campaignStats($cid);

where the variable "$q" has been previously loaded with values.

What I want to know is - can I programatically generate this line? What I'd
LIKE to do would be something like this (analogous to the way that DW builds
query strings) -

$statsQuery = 'campaign' . $command . "($cid)"

and then I can set $command to any of a number of different values, e.g.,
"ClickStats", "Bounces", "Unsubscribes", etc.

Now - what I don't know how to do is to then reference this string in a way
that executes the command, as I'm fairly sure that -

$stats = $q->$statsQuery; would fail (but I'm going to try it of course).

Is there a special way to handle such things?

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


This topic has been closed for replies.

3 replies

Inspiring
February 1, 2008
.oO(Murray *ACE*)

>Thanks, Micha!

You're welcome.

>My earlier imagined way didn't work, not surprisingly!

It would have required eval(), but usually you don't want to use that,
since eval() is evil and there's almost always a better way.

Micha
Inspiring
February 1, 2008
Thanks, Micha! My earlier imagined way didn't work, not surprisingly!

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Michael Fesser" <netizen@gmx.de> wrote in message
news:k7n4q39jppjrpi3sn2bcqvgdfu2s7g7geo@4ax.com...
> .oO(Murray *ACE*)
>
>>I am building a mini-app using an API into another back-end system. To
>>extract data from this system, I can use PHP lines like this -
>>
>>$stats = $q->campaignStats($cid);
>>
>>where the variable "$q" has been previously loaded with values.
>>
>>What I want to know is - can I programatically generate this line? What
>>I'd
>>LIKE to do would be something like this (analogous to the way that DW
>>builds
>>query strings) -
>>
>>$statsQuery = 'campaign' . $command . "($cid)"
>>
>>and then I can set $command to any of a number of different values, e.g.,
>>"ClickStats", "Bounces", "Unsubscribes", etc.
>>
>>Now - what I don't know how to do is to then reference this string in a
>>way
>>that executes the command, as I'm fairly sure that -
>>
>>$stats = $q->$statsQuery; would fail (but I'm going to try it of course).
>
> The function name can be taken from a variable, so you can use something
> like
>
> $statsQuery = "campaign$command";
> $stats = $q->$statsQuery($cid);
>
> For other ways of calling such "dynamic" functions have a look at
> call_user_func() and call_user_func_array() if necessary.
>
> Micha

Inspiring
January 31, 2008
.oO(Murray *ACE*)

>I am building a mini-app using an API into another back-end system. To
>extract data from this system, I can use PHP lines like this -
>
>$stats = $q->campaignStats($cid);
>
>where the variable "$q" has been previously loaded with values.
>
>What I want to know is - can I programatically generate this line? What I'd
>LIKE to do would be something like this (analogous to the way that DW builds
>query strings) -
>
>$statsQuery = 'campaign' . $command . "($cid)"
>
>and then I can set $command to any of a number of different values, e.g.,
>"ClickStats", "Bounces", "Unsubscribes", etc.
>
>Now - what I don't know how to do is to then reference this string in a way
>that executes the command, as I'm fairly sure that -
>
>$stats = $q->$statsQuery; would fail (but I'm going to try it of course).

The function name can be taken from a variable, so you can use something
like

$statsQuery = "campaign$command";
$stats = $q->$statsQuery($cid);

For other ways of calling such "dynamic" functions have a look at
call_user_func() and call_user_func_array() if necessary.

Micha