Moderators: phlip, Moderators General, Prelates
Sc4Freak wrote:The reason for using getters and setters is encapsulation. They protect clients of the class from changes in the internal implementation. You might want to add some debug checking whenever someone gets the width of a video, for example. Or you might want to enforce an invariant that width == height in the setter. Or whatever.
$size = $file->size;
$oldcontents = $file->contents;
// add new contents
$file->contents = "foo";
$file->save();
$size = $file->getSize();
$oldcontents = $file->getContents();
$file->setContents("foo");
$file->save();
// ...
if($file->contents = "foo"){
// ...
}
// ...
roband wrote:Mav is a cow.
RoadieRich wrote:The other solution there is always to write your comparrisons with a literal the other way round;
if ("foo" == $file->contents)
That way, it's again an error if you omit an equals sign. Or it should be, in most sensible languages - but then it is php we're talking about.
BotoBoto wrote:I don't know what's useful. I mean I want it to flow properly, be modular, and not hard to maintain. But I HATE examples which use bike
Steax wrote:The best rule of thumb is that whatever you're making, someone's already had to do it before. I abuse (modular) libraries to their limits. Go browse round them, take libraries you like, throw them somewhere in your server, and include them on-demand. Don't copy bits and pieces for each project. Just grab one and go.
For added obvious pointers, Flourish has a (cross-database) Database object, a session object, a permissions object, a rudimentary templating object (though you can just toss your own in, too), and you can use standard ORM for that user class.
There's also Moor that handles the Controllers part of MVC, so no more messing around with URL regexes in .htaccess files. There are many libraries that play friendly with others and are completely plug-and-play, so try them out.
Users browsing this forum: No registered users and 6 guests