![]() |
My Code?
I'm in the middle of coding a script, and before I want to continue, I want to make sure that my OOP at least conforms to what it should look like. Also, I noticed Haris has posted threads asking if his code looks good, so I figured it's worth a shot to post mine.
Keep in mind, this isn't nearly finished, I still have the whois function to make, and then also add in other features I have planned. Index: http://psdtocode.com/index.phps Whois Class: http://psdtocode.com/whois.class.phps A brief explanation on my whois output. I'm a neat freak when it comes to how my code looks, so I wanted to output it to look perfect. However, if I release this (probably unlikely), I'm going to get rid of that so it doesn't look weird in different layouts. |
Nice start Andrew, there's a few places where I'd like to point out some mistakes. The first mistake is your lack of member declarations, you have assigned a value to 2 member properties but there is no actual declaration for either property. Example:
PHP Code:
1) valdidates does not accept any function arguments 2) the arguments you try to pass through are already stored as member properties, thus you already have access to them inside the valdiates function Im guessing that was actually a mistake and wasn't intentional? Overall, nice start, good to see you trying to do this in OOP :) |
What do you mean in your bullet points? Should I pass them into the validate function as they are ($this->domain)? Is that supposed to give validate ability to use them? Sorry, new to OOP. :) I also was thinking about declaring those variables, yet wasn't exactly sure what to do for them. Thanks for the tips, will put them in use. :)
|
A couple of things to mention. Concerning your regular expression for checking the domains, I don't think such domains as .co.uk and .org.uk domains will validate. Also the hyphen character (-) is technically a regular expression character for range and therefore should be escaped. Although it would work fine in the instances you've used to it in.
Also, one more thing, just for making your code nice and tidy if you're particular - which it would appear you are, use the single quotes (see this article) when outputting the HTML, or the heredoc concept (which I personally dislike) makes it much neater: Single Quotes (Yum!) PHP Code:
PHP Code:
|
I did change it to single quotes, but the escaped characters for new lines and such didn't work, and I didn't want to have single quotes, then double quotes after the singles just to make those work.
Also, I was aware of those domains not working. I was talking with Salathe about it for a bit and realized it, which I still need to find a work around for. |
Just a little bit of information which might help you. You probably know this already (or wish you did) but the
explode function can have an optional third argument called limit. This enables you to limit the number of array elements returned. To put that into something visual:PHP Code:
If somewhere along the line you have 20 classes all with a display() method within them, it'll be a nightmare trying to debug the output and even worse if later on you decide that you want to offer both HTML and another form of output (XML, PDF, whatever). |
You also really want to check for if they enter the www. part of the domain which they could do, and act accordingly, else your extension is going to be incorrect.
PHP Code:
|
Thanks for all the help, I saw the limit part of explode on php.net, but never thought to look at it.
I'm actually thinking of dumping this project. It was a good idea I thought at first, but last night I was thinking maybe I'm doing too much trying to both learn OOP and even more techniques (doing whois with fsockopen), all at once. Thanks for all the help, and it will come in handy in the next project I'm planning. I'm doing to outline this one out first to make sure I have it all in my head. |
And you forgot the comments.
For including configuration and classes file, why not use include_once instead of include? That'll help producing error if you accidentally include them more than 1 time. |
I did one of these a year or so ago, and although the code's not that good any more (edit: updated it :)), it does still work. It may come in handy if you do decide to continue.
PHP Code:
|
Quote:
|
| All times are GMT. The time now is 07:39 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0