By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,158 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

Need confirmation

Airslash
100+
P: 221
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($this->parameters);
return;
}
}
throw new InvalidParameterException('Parameter was not found for the Command');
}
[/PHP]
Oct 7 '08 #1
Share this Question
Share on Google+
4 Replies


Markus
Expert 5K+
P: 6,050
Why don't you test it and tell us if it works?

Makes more sense.
Oct 7 '08 #2

Atli
Expert 5K+
P: 5,058
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.
Oct 7 '08 #3

Airslash
100+
P: 221
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.
Oct 7 '08 #4

pbmods
Expert 5K+
P: 5,821
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").
Oct 9 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.