Originally posted by GreyBoy
Heres what I want to know if you have a knowlage of OOP in php:
- Is it coded properly???
- Could and / or should I do something different???
- Is it documented well enough???
I fit this category.
1) I wouldn't say that it's coded poorly, what you have is well written.
2) Here is the downfall - You need to scrub your data. See example 1 below.
3) Yes however I recomend you give this a look http://utvikler.start.no/code/php_coding_standard.html and this too http://www.devshed.com/Server_Side/PHP/SelfDoc/page1.html
Ex: 1
<?php
//your original code
function setLinks()
{
$keys = explode(':',$this->linkTEXT);
$value = explode(':',$this->linkSRC);
$this->includes = array();
reset( $value );
foreach( $keys as $k ) {
list( , $val ) = each( $value );
$this->includes[$k] = $val;
}
}
?>
so what happens when the person passes in the following?
linkTEXT = "";
linkSRC = "";
linkTEXT = "One Link:Two Links";
linkSRC = "one.php:two.php:three.php";
???
Here is the best way to handle data scrubbing and error checking in OOP.
1) There are three types of errors:
a)Deadly - makes the script too unpredictable to carry on.
b)Failures - Function has failed irrecokably, but the program may be able to continue.
c)Warnings - The function has suceeded but it's data may be invalid.
2) devise a method for handleing each type of error.
a) Deadly errors should act up as soon as the file is included. You want the developer to get yelled at the second he tries to use the class or script. Two good examples of this are non-existent templates and non-existent tables.
b) Failures - have the function return a failure code (doesn't have ot be 0) that the programmer can grab and then work with. It is a good idea to develop a series of numbers that correspond to different errors so the calling program can react differently to different errors.
c) Warnings - the function returns succes but it set some internal stuff up so that the programmer can check and see if a warning was generated and which warning.
Remember when you build a class you are building a tool. This class might sit on a shelf for the next year befor it gets used again. You're not going to remember all the particulars and expectations the code has at that point so make sure the code knows what it expects.