Question regarding classes
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #2
RE: Question regarding classes
Yes, it's a hack, and something you probably generally "shouldn't" be doing.  It only really works because of how PHP works - well, PHP itself is bit of a quirky language which seems to borrow ideas from languages like C++ in which it shouldn't be, as a scripting language.

I do a number of other hacks as well, such as gaining control of objects etc.  Whilst I do try to avoid these types of hacks, sometimes it's impossible or very difficult to achieve something without them, or if you don't want people to have to perform a lot of code edits.

I honestly don't really know why MyBB wants to make use of private/protected variables - they don't really have a true separation of objects, which is what this is really useful for, and it makes plugins more difficult to write.

One example which comes to mind is string concatenation with the DB class - there really should be a $db->concat_string type function, rather than check the DB type every time a concatenation is needed.


Also, a scripting language doesn't quite fit too well with casual paradigms in compiled languages, for example, the getter/setter idea that a number of classes have:

PHP Code:
class A {
  private $var;
  public function setVar($val) { return $this->var = $val; }
  public function &getVar() { return $this->var; }
}

Whilst the above may have certain uses in C++/Java etc, in PHP, most of the time, it just adds a lot of overhead without actually improving anything.
In general, I don't think being pedantic about scope is really my way of doing things.


My Blog
07-27-2010 12:38 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
Question regarding classes - Pirata Nervo - 07-27-2010, 10:43 AM
RE: Question regarding classes - ZiNgA BuRgA - 07-27-2010 12:38 PM
RE: Question regarding classes - Technoman - 07-30-2010, 07:30 AM

 Standard Tools
Forum Jump: