0%
Loading ...

Parvesh Sandila

Parvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master's degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​

Databases in PHP

In the realm of server-side scripting, PHP stands out as a versatile language, capable of connecting and interacting with various database management systems like MySQL, Oracle, and PostgreSQL. PHP effortlessly facilitates CRUD operations—Create, Retrieve, Update, Delete—providing a streamlined approach to database manipulation. The fundamental purpose of databases, especially Databases in PHP, lies in information storage, and while there are multiple database management systems in the market, this tutorial series will exclusively delve into the nuances of MySQL Databases Choosing the Right Database for PHP What is MySQL? MySQL stands as a cornerstone in the realm of database management systems, particularly in conjunction with PHP, a dynamic server-side scripting language. Born out of the visionary mind of Michael Widenius on May 23, 1995, MySQL has evolved into a robust and widely embraced open-source relational database management system (RDBMS). Its nomenclature is a blend of personal sentiment and technical significance, with “MY” paying homage to the developer’s daughter and “SQL” denoting Structured Query Language, the backbone of database interactions. At its core, MySQL, a key player in Databases in PHP, employs a tabular structure for storing data, organized into tables comprised of rows and columns. This design facilitates efficient management and retrieval of information, adhering to the principles of relational databases. The tables act as repositories for data, allowing seamless execution of CRUD operations – Create, Read, Update, and Delete – through the power of SQL. MySQL Query Example: Please check the following example of a query to create a table in MySQL. In the above example, the CREATE TABLE query is used to create the Students table with id, name, email, mobile, and reg_date(columns).  Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Databases in PHP Read More »

Namespaces in PHP

In this tutorial, we will learn about Namespaces in PHP. Namespaces are mainly used to group classes that perform some similar kind of task. Furthermore, another benefit to using namespaces is we can use the same name for more than one classes in different namespaces. For example, suppose we have namespaces A and B both can have a class with the name Example in them. Declaring Namespace in PHP: PHP we use the namespace keyword to Declaring Namespace. Just write the namespace keyword followed by the namespace name. Please check out the following example program. <?php namespace Bank; ?> Please Note! declaring a namespace should be the first-line PHP file. Namespace Example Program: <?php //declaring name space. namespace SchoolNamespace; class Student{ function showStudent() { echo ‘Hello This showStudent method’; } } class Teacher{ function showTeacher() { echo ‘Hello This showTeacher method’; } } ?> Using Namespaces: We can use namespaces in two ways. From outside the namespace and within the namespace. Accessing Namespace class from outside:  $student = new SchoolNamespace\Student() Accessing class withing namespace: All the files which follow namespace declaration can use all the classes that belong to that particular namespace. <?php namespace SchoolNamespace; $student = new Student(); $teacher = new Teacher(); ?> Namespace Alias We can give an alias to class or namespace. which makes it easy to use them while writing code. To proving alias we use two keywords use and as. Giving a Namespace an alias: use SchoolNamespace as SN; $student = new Student(); $student->showStudent(); Giving a class an alias: use SchoolNamespace\Student as S; $student = new S(); $student->showStudent();   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Namespaces in PHP Read More »

Static Properties in PHP

In this tutorial, we will learn about Static Properties in PHP. Same as static methods we can declare static properties in PHP. We can access these static variables without creating an object of the class. Static properties can be declared using the static keyword. Please check out the following example program to know how to declare static properties. Declaring Static Properties Example Program: <?php class Example{ //This is static property public static $name = “Owlbuddy”; } ?> After declaring any static property you can access it very easily using the double colon(::) operator. Just write the class name that contains that particular property then a double colon(::) followed by property name. Please check out the following example program. Accessing Static Property Example Program: <?php class Example{ //This is static property public static $name = “Owlbuddy”; } echo Example::$name; ?> As you can see in the above example how easy it is to fetch static properties in PHP. Furthermore, there are many situations when you need to access any static property in the same class any method or constructor. In this kind of scenario, you can use the self keyword.  Fetching Static Property in Same class: <?php class Example{ //This is static property public static $name = “Owlbuddy”; public function show(){ echo “Welcome to “.self::$name; } } $obj = new Example; $obj->show(); ?> In the above example, we learned how we can access static properties in methods of the same class. But in case you want to access static properties from the parent class you have to use the parent keyword in the child class. Fetching Static Property from Parent class: <?php class Example{ //This is static property public static $name = “Owlbuddy”; } class Child extends Example{ public function show(){ echo “Welcome to “.parent::$name; } } $obj = new Child; $obj->show(); ?>   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Static Properties in PHP Read More »

Static Methods in PHP

In this tutorial, we will learn about Static Methods in PHP. As we know to call any method of class we must create an object of that particular class first. But we can call a static method without creating an object of the class. Creating a static method is easy as creating an instance method expect we write a static keyword before the function keyword. Please check out the following example program to know how to declare a static method in PHP. Defining Static Method Example Program: <?php class Example{ public static function hello() { echo “Hello, How are you?”; } } ?> to access these static methods we use double colon (::) operators. Accessing Static Method Example Program: <?php class Example{ public static function hello() { echo “Hello, How are you?”; } } // Calling to a static method Example::hello(); ?> We can access static method in other classes also but static method should be defined with public access. In many situations when you need to fetch static method in the same class in this kind of scenario you can use the self keyword. Please check out the following example program. Accessing Static Method in Same Class: <?php class Example{ public function __construct(){ // Calling to a static method using self keyword self::hello(); } public static function hello() { echo “Hello, How are you?”; } } $obj =new Example; ?> In case you want to fetch a static method from the Parent class you can use the parent keyword. Accessing Static Method from Parent Class: <?php class Example{ public static function hello() { echo “Hello, How are you?”; } } class Child extends Example{ public function __construct(){ // Calling to a static method using parent keyword parent::hello(); } } $obj =new Child; ?>   Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Static Methods in PHP Read More »

Traits in PHP

In this tutorial, we will learn about Traits in PHP. The trait is similar to a class but It isn't permitted to instantiate a Trait on its own. Traits are mainly used to declare methods that can be used in multiple classes. PHP only supports a single level inheritance(means we can inherit one class from another). But with the help of Traits, we can use freely use methods in different class hierarchies. In PHP we use trait keyword to declare a Trait. Please check out the following example code to know the basic syntax of Trait. <?php trait TraitOne{ public function hello() { echo “Hello User! “; } } ?> Now we will see how to use Trait in class. <?php trait TraitOne{ public function hello() { echo “Hello User! “; } } trait TraitTwo{ public function bye() { echo “Bye Bye! “; } } class Example{ use TraitOne; use TraitTwo; } $obj = new Example(); $obj->hello(); $obj->bye(); ?> Note! use keyword is used to access Trait in class. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Traits in PHP Read More »

Interface in PHP

In this tutorial, we will learn about Interface in PHP. The interface gives the ability to programmer to define what public methods a class should implement. An interface can contain only abstract methods it means we only declare methods names in the interface and after that, we define the body of these methods in a class that implements that particular interface. The interface contains no data variables. Multiple classes can implement to the same interface and this is known as polymorphism. The main idea to use interface in object-oriented programming is to force the class to override methods that are declared in the interface. Note! we define a class using class keyword. But to define an interface we use interface keyword in php Here is an example program that will help you to understand the basic syntax of an interface. Example Program: <?php interface StudentInterface { public function setData($name, $age); public function showData(); } Characteristics of Interface: The interface only contains abstract methods. All the methods of an interface must have public visibility scope. A class can inherit from one class but a class can inherit multiple interfaces. You do not need to write abstract keyword manually with methods in the interface.  The interface can not contain member variables(properties). Till now we have learned how we can define an interface in PHP. But here a question arises that how to use the interface after defining it. Using Interface in PHP: <?php interface StudentInterface { public function setData($name, $age); public function showData(); } class Student implements StudentInterface{ private $name, $age; function setData($name, $age){ $this->name=$name; $this->age=$age; } function showData(){ echo “Hello $this->name your age is $this->age”; } } $stu1 =new Student; $stu1->setData(“Ravi”,22); $stu1->showData(); ?> Note! to inherit a class in another class we use extends keyword but to implement and interface in class we use implements keyword. What if we do not override methods of the interface in a class:  <?php interface StudentInterface { public function setData($name, $age); public function showData(); } class Student implements StudentInterface{ function sayHello(){ echo “Hello user”; } } $stu1 =new Student; $stu1->sayHello(); ?> As in the above program, you can see methods of the StudentInterface interface are not overridden in Student class. That is why this program will not run but it will throw the following error message. PHP Fatal error: Class Student contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (StudentInterface::setData, StudentInterface::showData) Difference between Abstract class and Interface: Abstract class Interface An abstract class can have both abstract and non-abstract methods. But an Interface can have only abstract methods. An Abstract class can have both member variables. But Interface can not have member variables. An abstract class can have class methods like public, protected, etc. But in the case of interface, all methods must be public. We can implement an interface in an abstract class. But in an Interface can’t implement an abstract class. The abstract keyword is used to declare an abstract class. The interface keyword is used to declare an interface. To inherit the abstract class in our class we use the “extends” keyword. To inherit an interface in our class we use the “implements” keyword. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Interface in PHP Read More »

Abstract Class in PHP

In the dynamic world of PHP, abstract classes stand tall as powerful tools that allow developers to lay the groundwork for flexible and robust object-oriented programming (OOP) designs. These unique classes enable the creation of blueprints for other classes, fostering code reusability and promoting a structured development approach. In this article, we will delve into the realm of abstract classes in PHP, understanding their significance, exploring their key features, and engaging with practical examples to grasp their true potential. In case you do not have any idea about Method Overriding. Please click here to learn about Method Overriding in PHP. Unravelling Abstract Classes: An abstract class in PHP serves as a blueprint for other classes and cannot be instantiated on its own. It provides a foundation for its child classes to inherit, defining common attributes and method signatures. Unlike regular classes, abstract classes may contain both abstract and concrete methods, allowing developers to establish a structure that enforces consistent behaviour across the child classes. Declaring Abstract Classes in PHP: Let’s explore the process of creating an abstract class in PHP through an illustrative example. Consider a scenario where we want to build a shape hierarchy with an abstract class called, encompassing the fundamental properties and methods for various shapes. In the example above, we defined the Shape abstract class with an abstract method calculateArea() and calculatePerimeter(). Child classes extending this abstract class must provide concrete implementations for these abstract methods. Implementing Abstract Classes: To continue our example, let’s create concrete classes Circle and Rectangle that extend the Shape abstract class.  Advantages of Abstract class: Conclusion: Abstract classes in PHP provide a solid foundation for developers to build scalable and organized object-oriented applications. By creating abstract classes, developers can enforce consistent behaviour across derived classes while promoting code reusability and maintainability. Embrace the power of abstract classes in your PHP projects and embark on a journey towards efficient, structured, and extensible code. Happy coding! Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Abstract Class in PHP Read More »

Method Overriding in PHP

In the realm of object-oriented programming (OOP), method overriding is a crucial concept that empowers developers to modify and enhance the behaviour of inherited methods from parent classes. PHP, being a versatile and widely used language, fully supports method overriding, providing developers with a powerful tool to create flexible and maintainable code. In this article, we will embark on a journey to explore the concept of method overriding in PHP, uncover its benefits, and unleash its potential through engaging examples. If you don’t know about Inheritance, Please follow our tutorial on Inheritance. Click here to learn about Inheritance. Understanding Method Overriding: Method overriding is a fundamental concept in OOP that allows a subclass to provide a specific implementation for a method that is already defined in its parent class. By doing so, the subclass effectively replaces the inherited method’s behaviour, tailoring it to suit its unique requirements. Method overriding plays a pivotal role in achieving the “is-a” relationship in inheritance, where the subclass is considered a specialized version of the parent class. Implementing Method Overriding in PHP: Let’s dive into a practical example to grasp the essence of method overriding in PHP. Consider a Shape class with a method calculateArea() that calculates and returns the area of different shapes. In the example above, we have defined a Shape class with a method calculateArea(), which returns the area of a generic shape. The Circle and Square classes extend the Shape class and override the calculateArea() method to provide specific implementations for circles and squares. Advantages of Method Overriding: Conclusion: Method overriding is a powerful feature in PHP that empowers developers to create flexible and extensible code through inheritance. By understanding and utilizing method overriding, you can craft elegant and maintainable solutions for complex software development challenges. Embrace the potential of method overriding in your PHP projects and embark on a journey towards code excellence and efficiency. Happy coding! Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Method Overriding in PHP Read More »

Method Overloading in PHP

Method overloading is a fundamental concept in object-oriented programming that allows developers to define multiple methods with the same name but different parameter lists within a class. PHP, being a versatile and widely-used programming language, fully supports method overloading, offering developers flexibility and convenience in their code implementation. In this article, we will explore the concept of method overloading in PHP and provide illustrative examples to demonstrate its practical usage. What is Method Overloading? Method overloading allows developers to define multiple versions of a method in a class, differentiating them based on the number or type of parameters they accept. This powerful feature enables PHP developers to create more readable and maintainable code by providing a clear and descriptive interface for the various functionalities within their classes. Method Overloading in PHP: In PHP, method overloading is achieved by using the magic method __call() and __callStatic(). These methods are invoked automatically when an inaccessible or undefined method is called within a class instance or statically. Implementing Method Overloading: Let's consider an example of a Calculator class that performs arithmetic operations. We want to enable the Calculator class to support both single and double-operand operations. To achieve this, we will utilize method overloading.   class Calculator { public function calculate($a, $b = null) { if ($b === null) { // Single operand operation return $this->calculateSingleOperand($a); } else { // Double operand operation return $this->calculateDoubleOperand($a, $b); } } private function calculateSingleOperand($a) { // Perform the operation with a single operand return $a * $a; } private function calculateDoubleOperand($a, $b) { // Perform the operation with two operands return $a + $b; } } // Create a new instance of the Calculator class $calculator = new Calculator(); // Single operand operation $result1 = $calculator->calculate(5); echo “Result 1: ” . $result1 . “<br>”; // Output: Result 1: 25 // Double operand operation $result2 = $calculator->calculate(10, 7); echo “Result 2: ” . $result2 . “<br>”; // Output: Result 2: 17 In the example above, we defined a calculate() method in the Calculator class. Depending on the number of arguments passed, the method calls the appropriate private helper methods, calculateSingleOperand() or calculateDoubleOperand(), to perform the specific arithmetic operation. Benefits of Method Overloading: Improved code readability: Method overloading allows developers to use a single method name for different functionalities, making the code more expressive and easier to understand. Flexibility: The ability to handle multiple argument scenarios gives developers the freedom to implement complex functionalities in a unified manner. Reduced code duplication: By centralizing different versions of a method under a single method name, method overloading reduces code duplication and promotes maintainable codebases. Conclusion: Method overloading is a powerful feature in PHP that empowers developers to create versatile and concise classes. By understanding and leveraging method overloading, developers can improve the readability and maintainability of their code. As you continue to delve into object-oriented programming in PHP, keep method overloading in mind as a valuable tool in your programming arsenal. Happy coding! Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Method Overloading in PHP Read More »

Constants in PHP class

In this tutorial, we will learn about how to declare Constants in PHP class and fetch them using class objects. A constant is something like a variable used to store some value excepted the value of constants cannot be changed once it is declared. We can declare constants in PHP class using the const keyword. Please keep in your mind that constant identifiers are case-sensitive.  It is recommeded to write every constant name in upper case for example: MIN_AGE =10 How to define constants in PHP class: <?php class Rules { const MIN_AGE = “Minimum age to cast vote is 18”; } echo Rules::MIN_AGE; ?> As in the above example program you can see we used the const keyword to define a constant inside class and after that, we used the class name::(scope resolution operator) followed by the constant name to fetch the value of constant. How to access the value of constant inside a class: <?php class Rules { const MIN_AGE = “Minimum age to cast vote is 18”; function showAgeMessage(){ echo self::MIN_AGE; } } $rules =new Rules; $rules->showAgeMessage(); ?> As in the above example, you can see we used the self keyword to access the value of the constant inside the class. Parvesh SandilaParvesh Sandila is a passionate web and Mobile app developer from Jalandhar, Punjab, who has over six years of experience. Holding a Master’s degree in Computer Applications (2017), he has also mentored over 100 students in coding. In 2019, Parvesh founded Owlbuddy.com, a platform that provides free, high-quality programming tutorials in languages like Java, Python, Kotlin, PHP, and Android. His mission is to make tech education accessible to all aspiring developers.​ new.owlbuddy.com

Constants in PHP class Read More »

Scroll to Top
×