Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, imho PHP is a bad example for this because <a href="http://michaelkimsal.com/blog/php-is-not-object-oriented/" rel="noreferrer">PHP is not object-oriented</a>. Yes it has objects. Yes they support inheritance and all those OO principles. It supports objects. There's a difference.</p> <p>I say this because PHP doesn't by default exist in a state between requests. Every single HTTP request will completely recreate a PHP environment from scratch (which is reasonably cheap), meaning there is no static data persisted between requests. You might say "what about session data?" (and maybe append an "a ha!') but that isn't persistent data in a PHP sense either. It's (typically) stored in the filesystem and keyed by a cookie the client sends.</p> <p>Why do I mention these two things?</p> <p>Because the "global" scope in not like the global scope in C, Java, C++ or these other languages because they tend to persist between requests. PHP is more like the CGI programming model from the 90s (which is no coincidence because that's where it originated).</p> <p>So your objects aren't truly global: they are simply visible to all parts of the code servicing the current request.</p> <p>To me, that's nowhere near as bad. In fact, I often find it quite acceptable. Sometimes it's every necessary (eg in a callback to preg_replace_callback if you want to send information back to the caller or pass state to the callback without doing eval()/create_function() hacks).</p> <p>And the point about PHP not being object-<em>oriented</em> is because even in PHP 5 OO features are still somewhat "tacked on", meaning you could quite happily code away and code well in PHP without ever using them. This is different to, say, Java where you have to create a class even if all you do is write a bunch of static methods in it.</p> <p>So if you want to learn OO, honestly I wouldn't do it in PHP. PHP is good for a lot of things but it's designed to have an HTTP request lifecycle (yes I know you can run it from the command line but that's not what the vast majority of users do) and it's quite good at the job it's designed for.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload