PHP Magic Method __toString

PHP Magic Method __toString The __toString magic method contains the usual double underscore in its front. It does does as its name implies since it strips object characteristics. The next PHP OOP examples should help you understand the details. Integer Parameter With the first code block, an integer is passed into the class via the[…]

PHP Magic Methods __set and __get

PHP Magic Methods __SET and __GET With PHP OOP, you can manually set and get properties when you work with your object, or, you can use the __SET and __GET magic methods which are invoked automatically after you instantiate a class. If you want guaranteed results and plan to set property names outside the class,[…]

PHP Object Interfaces Keyword

PHP Object Interfaces Keyword Using object interfaces with PHP OOP is useful when you want to make sure a class must contain specific public functions. In other words, if you want to use an interface for a class, the class must use the method from the interface, otherwise an error will occur. Another key point[…]

PHP OOP Accessing Protected Properties

PHP OOP Accessing Protected Properties When you are using protected properties, they can be accessed with subclasses. However, if you want to print a protected variable from its parent class after you instantiate an object, you will receive a warning message. The easiest way to explain this is to show the following example. As you[…]

OOP Protected Functions PHP

PHP OOP Protected Functions

PHP OOP Protected Functions The whole essence of this brief tutorial is to emphasize that fact that protected functions cannot be used by an unrelated class. However, they can be used by a child class. With that said, the block of code will allow you to see a public function that is displayed in another[…]

Parse Json String Class Using PHP OOP

PHP Class To Parse Json String This class can be used to output desired data from a Json string. Here is how it works. The Json string is fed into the constructor within the ParseJson class. Then, the public convert_to_array() function is called while passing in the $this->jsonString property. Within the function, the Json string[…]

PHP Database Connection Class

  Simple Database Connection Class With PHP This tutorial is a bare bones login class that can be used to connect to a database so that you can execute custom queries. It consists of two files; one contains the actual Login class while the other file will instantiate a new object and gather a variable[…]