Question regarding classes
Pirata Nervo Offline
Member
***
Posts: 235
Joined: Jan 2008
Post: #1
Question regarding classes
Hi zinga,

Well I noticed in some of your plugins that you "bypass" the private keyword such as in the parse options.

What's the purpose of private/protected/etc if it still can be bypassed?
Or am I missing something?

I haven't tried it myself since I always respect if the property/method is private, protected or public but since you use it, it should work.
07-27-2010 10:43 AM
Find all posts by this user Quote this message in a reply
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
Pirata Nervo Offline
Member
***
Posts: 235
Joined: Jan 2008
Post: #3
RE: Question regarding classes
Okay thanks for the explanation Smile
07-28-2010 04:46 AM
Find all posts by this user Quote this message in a reply
Technoman Offline
Forum Idiot
Posts: 108
Joined: Jun 2010
Post: #4
RE: Question regarding classes
Zinga  
I read your last post and what you mentioned about php & c++ is true http://cboard.cprogramming.com/cplusplus...http://cboard.cprogramming.com/cplusplus-programming/118653-can-cplusplus-replace-php.html#

It could be easier to write a system using both languages...

Just remember I know nothing about coding but in real life you can have a word in different languages that are similar meaning, BUT in some languages there are certain words that do have a more powerful meaning of expression then others. Smile
(This post was last modified: 07-30-2010 07:39 AM by Technoman.)
07-30-2010 07:30 AM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #5
RE: Question regarding classes
(07-30-2010 07:30 AM)Technoman Wrote:  Just remember I know nothing about coding
No offense, but perhaps you should think twice about commenting on something you don't understand then.

My Blog
07-30-2010 06:45 PM
Find all posts by this user Quote this message in a reply
Pirata Nervo Offline
Member
***
Posts: 235
Joined: Jan 2008
Post: #6
RE: Question regarding classes
(07-30-2010 07:30 AM)Technoman Wrote:  Zinga  
I read your last post and what you mentioned about php & c++ is true http://cboard.cprogramming.com/cplusplus...http://cboard.cprogramming.com/cplusplus-programming/118653-can-cplusplus-replace-php.html#

It could be easier to write a system using both languages...

Just remember I know nothing about coding but in real life you can have a word in different languages that are similar meaning, BUT in some languages there are certain words that do have a more powerful meaning of expression then others. Smile

PHP is a scripting language. C++ is a programming language that must be compiled before you can run anything you code with it. They're completely different things (even though PHP was coded with C++), you can't just use both languages in the same code. Unless your C++ program also comes with a PHP parser, etc..
07-30-2010 07:51 PM
Find all posts by this user Quote this message in a reply
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #7
RE: Question regarding classes
You could use them together in a few ways (PHP extension, exec, etc), but that's not that important anyway...

My Blog
(This post was last modified: 07-30-2010 08:11 PM by ZiNgA BuRgA.)
07-30-2010 08:11 PM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

 Standard Tools
Forum Jump: