(Create a Community)
Sort by: Oldest
ehhm, that was way way too brief let me see if I can help to get into more detail Note: php4 ans php5 have different class-systems and they aren't compatible. I will be referring to php5 here. Objects are data structures which have a set of features which makes them very complex and very flexible at the same time, as example, data in objects has access privileges, objects may be created from others objects and, objects may have functions associated with them (which makes them a little more than just data). Well, in Object-Oriented Programming (OOP) classes are worked in two stages: declaration and instantiation (my english sucks ¬¬ I know); in Paul's example declaration is: [code=php] <?php class text_stuff { ... } ?>[/code] and instantiation: [code=php] <?php $txt = new text_stuff; ?>[/code] So, when we declare the class we are defining how that particular kind of objects should be, what they must have and what they must do; then we create an instance of that object that is like creating a variable but of a specific datatype (in this case the object we're referring to). Variables inside objects are called properties* and functions are called methods. The text_stuff class is one with three methods and no properties. let's redefine the text_stuff class to have a property: [code=php] <?php class text_stuff { public $available_tags = "b i u"; function make_bold($text) { return "<b>" . $text . "</b>"; } function make_italic($text) { return "<i>" . $text . "</i>"; } function make_underln($text) { return "<u>" . $text . "</u>"; } } ?>[/code] Well there it is, I've compacted a little the previous definitions but they're the same in every aspect; now the property can be accesed the same way as the methods with the '->' operator as we've seen before: [code=php] <?php echo $txt->available_tags; ?>[/code] so now we can know which operations is capable this class. (it's a very lame example ¬¬ granted, my imagination is running low at this moment). What about that "public" keyword that just appeared there? well that is the access privilegies that I was saying at the beginning, this is called visibility and it's a way to control who can have access to that property. There are three access modes: public, private and protected; public mode is the one we've been using till now, this mode grants access to the property to any procedure who is in scope of the object's instance, this is, if you can reach $txt then you can access any public properties it may have; private mode works in a different way, it limits the access to the property to only the methods of that class, this in our example means that if we were defined $available_tags as private the only ones who may be able to access it should be make_bold(), make_italic() and make_underln() (in fact the line "echo $txt->available_tags;" will generate an error); the protected mode won't be discussed now, it's only relevant when inheritance enters the game, by the moment let's say that it works like protected. Access privilegies not only apply to properties but as methods as well, in the case of methods if we ommit the visibility keyword php assumes it is public (this is actually a very stupid and inconsistent behavior of php of allowing a default visibility for methods and forbidding it for properties but whatever ). Why should we want to "hide" some properties and/or methods** in a class? well that depends on our particular purpose for the class itself but there is a primary reason for hiding properties and that is, once we have access to a public property that access is not limited to reading only but to writing too, that means that we're able to modify the object's properties values at runtime and that may be troublesome in some cases, in our example $available_tags tells us which html tags are supported by that class, if we use that value to set up an error handler as part of our application and somewhere else some asshole by mistake writes a different value to that property it will make the app crash and we won't be able to find the bug in our source xDDD that is pretty scary in fact, well the solution is to set $available_tags as private and create a public method to read it, this way we ensure a read-only access to the property: [code=php] <?php class text_stuff { private $available_tags = "b i u"; // function to read private property $available_tags function get_available_tags() { return $this->available_tags; } function make_bold($text) { return "<b>" . $text . "</b>"; } function make_italic($text) { return "<i>" . $text . "</i>"; } function make_underln($text) { return "<u>" . $text . "</u>"; } } ?>[/code] and we'll use it like this: [code=php] <?php echo $txt->get_available_tags(); ?>[/code] But now we've introduced another new concept, what about that $this right there? well $this is a reserved keyword that works like a reference to the current object from inside it, this is because each instance of an object has it own values for it's properties, but to see this we'll declare another class: [code=php] <?php class circle_stuff { public $radius = 0; function get_perimeter() { return 2 * pi() * $this->radius; } function get_area() { return pi() * $this->radius * $this->radius; } } $circle1 = new circle_stuff; $circle1->radius = 2; $circle2 = new circle_stuff; $circle2->radius = 3.5; echo "Circle1\n"; echo "radius: " . $circle1->radius . "\n"; echo "parimeter: " . $circle1->get_perimeter() . "\n"; echo "area: " . $circle1->get_area() . "\n"; echo "\n"; echo "Circle2\n"; echo "radius: " . $circle2->radius . "\n"; echo "parimeter: " . $circle2->get_perimeter() . "\n"; echo "area: " . $circle2->get_area() . "\n"; ?>[/code] Here things are viewed from a different angle than the previous example, in the text_stuff class the idea was to have some functions that process text in the class and feed them with some text to be processed, there makes very little sense to have more than one instance of the class since they will be all exactly identical but here we're saving particular data in each instance hence making them unique and so applying the functions to the instance's saved value of the data, and there is when $this comes in handy because it returns a reference to the current object independent of where we're calling it (which instance) so it allows us to create generic functions that act directly in the instance they're referred to and so, avoiding parameters. Well I think this is enough by now, there is a lot more to say about classes, mayb later. C'ya! * php.net seems to call them members instead of properties but whatever, they're called properties in almost every other language ** this "hiding" is formally known as "data encapsulation"
PHP - Posted By Samus_ - Karma received: 1
I hate this: http://img218.imageshack.us/my.php?image=shuzakshotpu4.png, as you can see I'm in a 800x600 resolution (no questions plz) and the "Related Topics" box pops over my message ¬¬ This is one of the things I hope to fix ...once I get to the code 8-)
Shuzak Current Affairs - Posted By Samus_ - Karma received: 2
eurodance yeah!
Techno - Posted By Samus_ - Karma received: 1
I have a question, I haven't seen the sources yet so I cannot be sure but does not this javascript function implies that you're sending raw html as a request? I think this emot-translation should always be made by php since sending html as a request is usually a very big security risk.
Suggest Shuzak! - Posted By Samus_ - Karma received: 0
(something strange with the earlier post ¬¬ I will write again) Shuzak references from the site my post in web2.0: http://web2.reddit.com/info/19b6p/comments an article from the blog of jawad (are you python_kiss? ): http://reddit.com/info/vlpe/comments and some idiot who made a mistake when posting ¬¬: http://programming.reddit.com/info/eza7/comments (I'm trying to get this one deleted so we can repost with the right title)
reddit - Posted By Samus_ - Karma received: 1
reddit - Posted By Samus_ - Karma received:
and you were using Google Earth to sell Pirated CDs? :o!!!!!! (btw: wtf? xd) okey, now the right link for the main reddit's page: http://reddit.com/info/19bwn/comments
reddit - Posted By Samus_ - Karma received: 0
ehhhm guess what? xD you're not serving the files as text/plain EDIT: perhaps it's a beta for testing, I thought that it may be the source
Shuzak's Collaborative Program - Posted By Samus_ - Karma received: 0
please confirm when the first non-filler episode is out (yes, I'm THAT pissed off ¬¬)
Anime - Posted By Samus_ - Karma received: 0
Shuzak's Collaborative Program - Posted By Samus_ - Karma received:
Shuzak's Collaborative Program - Posted By Samus_ - Karma received: 0
a dream about games? I don't know yet how to become aware of the dream when you're on it but, if by casuality you do there is two basic things NOT to do to stay there, first don't get excited when you're asleep the brain is relaxed, when you're awake it's not so if you realize that you're dreaming try to be as much calm as you can or else the dream will fade out and you will be awake at once. second thing not to do is trying to move as you usually do in the real plane, one important thing to understand is that in your dream you probably will have a body but that's not your real body, your real body is still lying down on bed and if you "move" as usually do you will be moving your physical body instead and that will make you awake too; so to move in your dream what you must do is to move mentally, this is, move with your imagination your mental image of your body (that is, the body you have in the dream), this is pretty confusing at first; one kind of exercise that may help to practice is being awake, close your eyes and try to "feel" your body, once you do try to move with your mind that mental image of the body without moving the real one that's kinda what you do in the lucid dream. Using this same principle you can reshape your body too, but that's a little weird (especially if you transform into something you have no idea how it's supposed to move xDDDDD)
Life - Posted By Samus_ - Karma received: 1
:o!! this is damn interesting, I'll try to manage my time to be around more and see if I can help in some way. Very good initiative
Shuzak's Collaborative Program - Posted By Samus_ - Karma received: 1
good links, most of them I didn't knew check this site: http://dailyepisodes.com/index.php?s=1 it used to be like peekvid but some day someone posted it at reddit and it was taken down by Fox ¬¬ now it's a link repository for other sites of this kind. Just a remainder of why some sites must NOT be very public.
Anime - Posted By Samus_ - Karma received: 0
http://www.flazx.com/ - http://www.flaxstor.com/blog/ and this: http://www.programmingbooks.org/ is 'kind-of' a user-generated rank of programming books P may be useful to spot something good to read.
Programmers - Posted By Samus_ - Karma received: 0
(not sure if this is a "bug-report" topic ) well, just wanted to say that when I paste a link my session is not recognized, pretty strange because I don't get logged out, just that if I don't reach the page thru browsing it does not recognize the session. The cookie is there also UPDATE: it's working fine now
Suggest Shuzak! - Posted By Samus_ - Karma received: 0
lol I'm famous!
Suggest Shuzak! - Posted By Samus_ - Karma received: 0
thank you too! good job_
Suggest Shuzak! - Posted By Samus_ - Karma received: 0
hope this helps: http://xkr.us/articles/javascript/encode-compare/
Suggest Shuzak! - Posted By Samus_ - Karma received: 2
I think a "preview" may be a good option -I'm just enlarging your TODO list I know... and I love it >D -
Suggest Shuzak! - Posted By Samus_ - Karma received: 1