Even ee might think your poetry a little opaque.
Buffistas Building a Better Board
Do you have problems, concerns or recommendations about the technical side of the Phoenix? Air them here. Compliments also welcome.
Even ee might think your poetry a little opaque.
I say "ee", you say "OO", let's call the whole thing off.
And of course like all Perl addicts I've realised I was way wordy above, goddamnit I'm Samuel Taylor Coleridge compared to the Japanese simplicity of this:
@newarray = grep {/./} @oldarray;
What was I thinking! If all I need is the output, I don't even need the new array:
print(grep(/./,@oldarray);
I distinctly recall John promising to use his powers only for good. This is not for good.
All I'm saying is, when you're used to stuff like that, everything in PHP starts to seem overly prolix.
So, who's beta-tested the bloody HTML parser anyway? Did it work, did it fail, did it die, what? I'm sulking.
The next stage would presumably be to transform my code, which just looks like this:
$content = stuff in the form;
do something to it
do something else to it
[20 more lines of the same]
$output = required tags;
into that new Object-Oriented code you young whippersnappers love so much. Get off my lawn!
What's the right way to do it, something like:
$check = new htmlCheck();
if($check.parse(stuff in the form) == 'no probs'){everthing's fine}
kind of thing?
And then write an object that that does all that stuff with a parse method, and returns either 'no probs' or a list of tags?
Since none of the young whippersnappers seem to want to answer, this old fogey will take a shot.
I'd write the parse method to return the form content plus any tags needed to close unclosed tags. For extra credit, I'd add another method that returns whether the last call to parse had to add any tags. The latter method could be used if we decide to tell users that they are forgetting to close a tag.
I like this api slightly better because if you end up having to rewrite the middle portion of the form contents, you can do it. If you just return a list of tag closers, you're limited to fixing problems that can be fixed just by appending stuff. Which won't work if we try to attack the attribute quoting problem.
That makes sense, so we have a method which is
something.parse()
and it returns parsed/fixed content, and we have another one which is
something.neededFixing()
which returns true or false?
Or do we need a "something.parse()" which returns two things, the content and the boolean for neededFixing?
Either works, having two separate functions is easier, unless PHP provides some wait of returning two separate return values to a single function.
in C++, it might be
pair<bool,string> parse(const string& formContent);
but I don't know how to do that in PHP.
When I get back home I'm going to learn how to use PHP. Maybe I'll take on one of those new features people want as a learning exercise.
having two separate functions is easier
That makes sense, but also means the whole routine has to be run again, just to get a true or false value.
unless PHP provides some wait of returning two separate return values to a single function
I don't see why not. You can return more than one thing, surely? Now I'm not sure. I'll go and check.
The simplest thing to do would be to return an array.