PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > problem calling functions
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
problem calling functions

Réponse
 
LinkBack Outils de la discussion
Vieux 19/10/2007, 16h15   #1
afan pasalic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut problem calling functions

hi
I have a problem with calling functions:

<?php
function solution1($var1) {
// some code
}

function solution2($var2) {
// some code
}

function solution3($var3) {
// some code
}

if ($function == 'solution1' or $function == 'solution2' or $function ==
'solution3')
{
$my_solution = $function($var); # this supposed to call one of
"solution" functions, right?
}
?>

suggestions?

thanks.

-afan
  Réponse avec citation
Vieux 19/10/2007, 17h09   #2
afan pasalic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] problem calling functions



Robin Vickery wrote:
> On 19/10/2007, afan pasalic <afan@afan.net> wrote:
>
>> hi
>> I have a problem with calling functions:
>>
>> <?php
>> function solution1($var1) {
>> // some code
>> }
>>
>> function solution2($var2) {
>> // some code
>> }
>>
>> function solution3($var3) {
>> // some code
>> }
>>
>> if ($function == 'solution1' or $function == 'solution2' or $function ==
>> 'solution3')
>> {
>> $my_solution = $function($var); # this supposed to call one of
>> "solution" functions, right?
>> }
>> ?>
>>
>> suggestions?
>>

>
> suggestions for what?
>
> What is your problem? If you set $function to 'solution1' and run your
> code, it will indeed execute solution1().
>
> -robin
>


the problem is that this code doesn't work. and I was asking where is
the problem, or can I do it this way at all.
:-)

-afan
  Réponse avec citation
Vieux 19/10/2007, 17h11   #3
afan pasalic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] problem calling functions


Jay Blanchard wrote:
> [snip]
> <?php
> function solution1($var1) {
> // some code
> }
>
> function solution2($var2) {
> // some code
> }
>
> function solution3($var3) {
> // some code
> }
>
> if ($function == 'solution1' or $function == 'solution2' or $function ==
> 'solution3')
> {
> $my_solution = $function($var); # this supposed to call one of
> "solution" functions, right?
> }
> ?>
> [/snip]
>
> I don't think you can put a function name in a variable and call it like
> $function($var). You'd be better of with a case statement in one
> function and call the proper solution (quick syntax, may need a little
> fixing;
>
> function my_solution($function, $var){
> switch $function{
> case function1:
> ...do stuff...
> break;
> case function1:
>
>
> etc.....
> }
> }
>


that's exactly what I'm doing now. though, I was thinking if it's possible.
:-(

thanks jay
  Réponse avec citation
Vieux 19/10/2007, 17h13   #4
afan pasalic
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] problem calling functions

Jay Blanchard wrote:
> [snip]
> [snip]
> <?php
> function solution1($var1) {
> // some code
> }
>
> function solution2($var2) {
> // some code
> }
>
> function solution3($var3) {
> // some code
> }
>
> if ($function == 'solution1' or $function == 'solution2' or $function ==
> 'solution3')
> {
> $my_solution = $function($var); # this supposed to call one of
> "solution" functions, right?
> }
> ?>
> [/snip]
>
> I don't think you can put a function name in a variable and call it like
> $function($var). You'd be better of with a case statement in one
> function and call the proper solution (quick syntax, may need a little
> fixing;
>
> function my_solution($function, $var){
> switch $function{
> case function1:
> ...do stuff...
> break;
> case function1:
>
>
> etc.....
> }
> }
> [/snip]
>
> And call it like this;
>
> my_solution('function1', $var);
>


actually, I did a little bit different:

switch($function)
{
case 'solution1':
solution1($var1);
break;

case 'solution2':
solution2($var2);
break;

case 'solution3':
solution3($var3);
break;
}



;-)

-afan
  Réponse avec citation
Vieux 19/10/2007, 17h24   #5
Robin Vickery
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] problem calling functions

On 19/10/2007, afan pasalic <afan@afan.net> wrote:
> hi
> I have a problem with calling functions:
>
> <?php
> function solution1($var1) {
> // some code
> }
>
> function solution2($var2) {
> // some code
> }
>
> function solution3($var3) {
> // some code
> }
>
> if ($function == 'solution1' or $function == 'solution2' or $function ==
> 'solution3')
> {
> $my_solution = $function($var); # this supposed to call one of
> "solution" functions, right?
> }
> ?>
>
> suggestions?


suggestions for what?

What is your problem? If you set $function to 'solution1' and run your
code, it will indeed execute solution1().

-robin
  Réponse avec citation
Vieux 19/10/2007, 17h24   #6
Zoltán Németh
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] problem calling functions

2007. 10. 19, péntek keltezéssel 11.15-kor afan pasalic ezt Ãrta:
> hi
> I have a problem with calling functions:
>
> <?php
> function solution1($var1) {
> // some code
> }
>
> function solution2($var2) {
> // some code
> }
>
> function solution3($var3) {
> // some code
> }
>
> if ($function == 'solution1' or $function == 'solution2' or $function ==
> 'solution3')
> {
> $my_solution = $function($var); # this supposed to call one of
> "solution" functions, right?
> }
> ?>


what's wrong with this?

greets
Zoltán Németh

>
> suggestions?
>
> thanks.
>
> -afan
>

  Réponse avec citation
Vieux 19/10/2007, 17h33   #7
Jay Blanchard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [PHP] problem calling functions

[snip]
<?php
function solution1($var1) {
// some code
}

function solution2($var2) {
// some code
}

function solution3($var3) {
// some code
}

if ($function == 'solution1' or $function == 'solution2' or $function ==
'solution3')
{
$my_solution = $function($var); # this supposed to call one of
"solution" functions, right?
}
?>
[/snip]

I don't think you can put a function name in a variable and call it like
$function($var). You'd be better of with a case statement in one
function and call the proper solution (quick syntax, may need a little
fixing;

function my_solution($function, $var){
switch $function{
case function1:
...do stuff...
break;
case function1:


etc.....
}
}
  Réponse avec citation
Vieux 19/10/2007, 17h38   #8
Jay Blanchard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RE: [PHP] problem calling functions

[snip]
[snip]
<?php
function solution1($var1) {
// some code
}

function solution2($var2) {
// some code
}

function solution3($var3) {
// some code
}

if ($function == 'solution1' or $function == 'solution2' or $function ==
'solution3')
{
$my_solution = $function($var); # this supposed to call one of
"solution" functions, right?
}
?>
[/snip]

I don't think you can put a function name in a variable and call it like
$function($var). You'd be better of with a case statement in one
function and call the proper solution (quick syntax, may need a little
fixing;

function my_solution($function, $var){
switch $function{
case function1:
...do stuff...
break;
case function1:


etc.....
}
}
[/snip]

And call it like this;

my_solution('function1', $var);
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 16h02.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,14242 seconds with 16 queries