Php classes, functions (static and public) explained with an analogy which can be understood by someone who knows CSS (and SCSS)?
PHP Classes, static functions, and public functions.
Right now, I just understand what functions are (no idea what happens if they are static or public).
According to what I know a function would be the equivalent of a CSS selector:
function dos开发者_StackOverflow社区omestuff {
}
#selector {
declaration: ;
}
What would be a good CSS (or SCSS) analogy for the classes, static functions, and public functions?
As comments have pointed out, you're really talking about apples and oranges here. A function doesn't share much in common with a selector at all, nor are there any other particularly good analogous relationships between CSS and PHP. They're very different tools that do very different things.
For definitions of things like "static" and "public" you'll want to approach the subject from scratch (not trying to fit it into something else you already know) and learn about object oriented programming.
But just to give you a quick reference on at least those two terms:
A "public" function (or member variable) is one that can be accessed by (or from) any other class or function. It's an open and accessible part of the interface (or contract) for that class. This is as opposed to other terms such as "protected" (which means it can only be accessed internally to that class or by classes which inherit from that class) and "private" (which means it can only be accessed internally to that class).
A "static" function (or member variable) is one that can be accessed without requiring an instance of that class. (As opposed to an "instance" function or member variable, which is the default and doesn't need a qualifier to specify that behavior.) For example, if you have a class called Car which has an instance function and a static function, you could call the static function anywhere at any time but you would need to first "create" a Car to call the instance function on it.
The static function wouldn't have any logic that relies on an existing instance of a car, whereas the instance function would. For example, the static function might just return a blueprint of the model of that car, whereas the instance function might honk the horn of the car. A car needs to first exist before the horn can be honked, but the blueprint is just a piece of information globally known about the car.
These descriptions are pretty vague and broad, and there is much better study material on the subject. I only offer these as an example of how not like CSS this is.
精彩评论