Dynamische "if-Bedingung"

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dynamische "if-Bedingung"

    Hallo zusammen,

    habe folgendes Problem:

    Ich möchte Methodenaufrufe dynamisch an bestimmte Vorbedingungen binden.

    Zur Verdeutlichung wie ich mir das vorgestellt habe:

    $precondition = "\$_POST[\"country\"] != \"\"";
    if($precondition) {
    Methodenaufruf;
    }

    Hat jemand eine Idee wie ich dies codieren kann, und ob dies überhaupt möglich ist?

    Wie es nicht funktioniert und was ich schon ausprobiert habe:

    if({$precondition}) {
    Methodenaufruf;
    )

    if(evals($precondition)) {
    Methodenaufruf;
    )

    Besten Dank schon mal für eure Hilfe

  • #2
    müsste z.B. mit eval so funktionieren:
    PHP Code:
    if (eval("return (\$_POST[\"country\"] != \"\") ? true : false")) {
      
    // mache was sinnvolles

    /edit: sehe gerade das VBB hat ein Problem mit Smilies im PHP-Code (war am ende des Kommentars

    Comment


    • #3
      warum nicht einfach
      PHP Code:
      if (isset($_POST['country']))
      // oder mit empty überprüfen 

      Comment


      • #4
        Hier die Lösung für mein Problem:

        PHP Code:
        $precondition "\$_POST[\"country\"] != \"\"";
        if( eval(
        "return " .$precondition";")  ) {
              
        Methodenaufruf;

        Comment


        • #5
          Original geschrieben von blackbean
          Hier die Lösung für mein Problem:

          PHP Code:
          $precondition "\$_POST[\"country\"] != \"\"";
          if( eval(
          "return " .$precondition";")  ) {
                
          Methodenaufruf;

          was soll das denn machen? Nur prüfen ob Country nicht leer ist?

          Wenn ja, Einfacher:
          PHP Code:
          if(!empty($_POST['country']))
          {
          //Ausgabe wenn Country nicht leer ist, etc.

          mfg
          marc75

          <Platz für anderes>

          Comment

          Working...
          X