Need confirmation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Airslash
    New Member
    • Nov 2007
    • 221

    Need confirmation

    Hello,

    I just wish to have confirmation if this snippet of PHP code will actually function properly. It's part of my SqlCommand class, and sort of acts like the SqlCommand in C#.NET.

    It should remove a SqlParameter from the Command's internal array of parameters, but I've read somewhere that using a return inside a loop will not always work, so here's the function I wrote.

    open for feedback/ suggestions


    [PHP]
    final public function removeParameter (SqlParameter $parameter) {
    for($i = 0; $i < count($this->parameters); $i++) {
    if($parameter->equals($this->parameters[$i])) {
    unset($this->parameters[$i]);
    $this->parameters = array_values($t his->parameters);
    return;
    }
    }
    throw new InvalidParamete rException('Par ameter was not found for the Command');
    }
    [/PHP]
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Why don't you test it and tell us if it works?

    Makes more sense.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Originally posted by Airslash
      It should remove a SqlParameter from the Command's internal array of parameters, but I've read somewhere that using a return inside a loop will not always work, so here's the function I wrote.
      If the code reaches the return keyword, it will work.
      Whether or not it actually reaches the keyword depends on your loop.

      Comment

      • Airslash
        New Member
        • Nov 2007
        • 221

        #4
        Originally posted by Markus
        Why don't you test it and tell us if it works?

        Makes more sense.
        don't have any direct examples to use it in. It's still in development and don't have any running scripts to use it in.

        Aptana doesn't give any syntax errors, but don't know if I can trust it.
        If I ever get to testing it I'll let you know. Was just hoping if someone tried a similar script and could share his experience with it.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Airslash.

          return inside a loop works just fine.

          Try running php -l (that's a lowercase 'L') on your script. That will cause PHP to "lint" your file (check for syntax errors; dunno why it's called "linting").

          Comment

          Working...