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.​

Inheritance in PHP

In this tutorial, we’ll dive into Inheritance in PHP. It’s a way to inherit properties and methods from one class to another, allowing us to create a new class with its features, plus all the attributes of its parent class. During inheritance, you’ll encounter two types of classes Note, extends keyword is used to perform inherit Available Types of Inheritance in PHP: Those who have background in c++ might be missing Multiple Inheritance. But Multiple Inheritance is not available in PHP. Single Level Inheritance: In single-level inheritance, one class is inherited into another, with one serving as the parent class and the other as the child class. This straightforward form of inheritance is commonly referred to as simple inheritance. Example Program: In the example program above, notice that the $name variable and set_name() method are not explicitly written in the Student class. However, we can access them using the object of the Student class. This happens because, after inheriting the Person class in the Student class, the properties and methods seamlessly become part of the Student class. Multilevel Inheritance: In this form of inheritance, more than two classes are involved. In Multilevel inheritance, a parent class is inherited by a child class, and then this child class becomes the parent for another child class. This creates a chain of inheritance, extending the features through multiple levels. In above scanrio, B is parent of C class and also A is indrect parent of C class. Example Program: Hierarchical Inheritance: In Hierarchical Inheritance, a single class inherits from more than one class. This creates a branching structure where multiple child classes inherit from a common parent class. Check the illustration below to better grasp this concept. Example Program: 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

Inheritance in PHP Read More »

Access Modifiers

In this tutorial, we will learn about Access Modifiers. Access Modifiers are used to control the accessibility of properties and methods. For example, you want to create a method that you do not want to make accessible from outside of the class. You can easily do this with the help of Access Modifiers. Types of Access Modifiers:  There are three types of Access Modifiers in PHP, which are as follow.  public protected private Public:  This is the default access modifier in PHP. In case you do not write any access modifier with the method or property default access modifier will be there by default. Any property or method with a default access modifier can be accessed from everywhere.  <?php class Example { //variable with default access public $var = “Python”; } $obj = new Example(); echo $obj->var; ?> Protected:  A method or property with protected access modifier can be accessed from with the class or in classes that are inheriting to that particular class. To apply a protected access modifier on your property or method you have to write a protected keyword along with an identifier. To understand the protected access modifier please check the following example program. <?php class Example { //variable with protected access protected $var = “Owlbuddy Programming Tutorials”; function show(){ echo $this->var; } } $obj = new Example(); //will work Normally $obj->show(); //will throw an Error (Please Uncomment following line to check) //echo $obj->var; ?> Private: Any method or property with a private access modifier can be accessed only inside the class where it is defined. Please check out the following program to understand it. <?php class Example { //variable with private access private $var = “Owlbuddy Programming Tutorials”; function show(){ echo $this->var; } } $obj = new Example(); //will work Normally $obj->show(); //will throw an Error (Please Uncomment following line to check) //echo $obj->var; ?>   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

Access Modifiers Read More »

PHP Destructor

In this tutorial, we will learn about PHP Destructor. The destructor method is totally reverse of the constructor method. PHP destructor does not return any value. In case we create __destructor function in class, PHP will automatically call the destructor function if there are no other references to a particular object or at the end of the script. Please Note, that the desructor function starts with two underscores (__). for e.g. __destruct() Here an example program to show how to define destructor in PHP. <?php class Example { //defing a constructor function __construct() { echo “This is constuctor method.<br>”; } //defing a normal method function show(){ echo “This is show method.<br>”; } //defing a destructor function __destruct() { echo “The is destructor method.<br>”; } } $obj = new Example(); $obj->show(); $obj->show(); $obj->show(); ?> The destructor will be called even if script execution is stopped using exit() or die() function. Difference b/w Constructor and PHP Destructor: Constructor Destructor It Allocates Memory It Deallocates Memory Get called at the time of class is instantiated Get called at the time of deletion of the object Name of function is _construct(). Name of function is _destruct() Can accept parameters  Can not accept parameters  Constructors can be overloaded  Destructors can not be overloaded   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

PHP Destructor Read More »

PHP Constructors

In this tutorial, we’ll explore the PHP Constructors, a special function within a class. Its primary purpose is to initialize the properties of each object instance. The constructor is remarkable because it’s automatically invoked when a new object is created. Let’s delve into the details of this essential feature. Please Note, that the construct function starts with two underscores (__). Here you can check an example program to understand how to create a constructor in PHP: Types of Constructor: Default Constructor:  A constructor with no parameters is referred to as the default constructor. While it can be used to initialize class properties, it also allows for calling other member functions within the class. This flexibility enhances the default constructor’s utility in managing class behaviour. Parameterized Constructor: A constructor with parameters is called a parameterized constructor. This allows us to provide different values to initialize the data members of the class. The example program below illustrates how to use a Parameterized PHP Constructor, making it easier to grasp the concept. Copy Constructor: The copy constructor is used to create a duplicate of an already existing object. It accepts the address of another object as a parameter, allowing for the creation of an identical copy. 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

PHP Constructors Read More »

PHP Classes and Objects

In this tutorial, we will learn about PHP Classes and Objects. As we know Object-oriented programming is a programming paradigm, based on the concept of classes and objects. In very easy language a class is the blueprint of the object and an object is a run time instance of that class. Let's check how to define a class and create an object in PHP. Defining a class: In PHP, the class keyword is used to define a class. We write the class keyword followed by the class name and after that, we define the properties and methods of the class in curly braces {}. Please check out the following example program to understand this. <?php class Student { // proerties and methods will come here… } ?> In the above example program, you can see how we have created a Student class. For good coding practice always write class name starting from captial letter.  For e.g. Student, Person, Car etc. We can define properties and methods in the class. Please check out the following program. <?php class Student{ // Properties public $name; public $age; // Methods function set_properties($name, $age) { $this->name = $name; $this->age = $age; } function get_properties() { echo $this->name.’ ‘.$this->age; } } ?> Creating an Object in PHP: An object is a run time instance of the class. We can create multiple objects of any class and each object will have all the properties and methods defined in the class. Each object will occupy a different space in memory and each object have the ability to set different values for properties. In PHP we use the new keyword to create objects of the class. Please check out the following example program to understand the concept of objects wisely. <?php class Student{ // Properties public $name; public $age; // Methods function set_properties($name, $age) { $this->name = $name; $this->age = $age; } function get_properties() { echo $this->name.’ ‘.$this->age; } } //creating objects using new keyword $student1= new Fruit(); $student2 = new Fruit(); //calling to set properties method of Student class $student1->set_properties(‘Rahul’,19); $student2->set_properties(‘Mohit’,20); //calling to get properties method of Student class echo $student1->get_properties(); echo “<br>”; echo $student2->get_properties(); ?>   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

PHP Classes and Objects Read More »

What is PHP OOPs

In this tutorial, we will learn about What is PHP OOPs. OOP stands for Object-Oriented Programming. Object-oriented programming is a programming paradigm based on the concept of classes and objects. By using the OOPs approach we can divide the software program into simple, reusable pieces of code(known as a class). The classes are used to create individual instances of objects. Difference between Class and Objects: Class is like the blueprint to create instances of the object and we can create multiple instances of a class. Please check out the following illustration to understand the concept of class and objects more wisley. Important Object-Oriented Concepts: Class  Object Member Variable  Member function  Inheritance Polymorphism Encapsulation Inheritance 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

What is PHP OOPs Read More »

Date in JavaScript

In this tutorial, we will learn Date in JavaScript. JavaScript Date method helps us to do various basic functions like to get the current date, time and year. We can also add timers on the Web pages with the help of the date object. Date object provides us with four types of constructors we can use any according to our requirement to create an object of Date. It also has a lot of methods which we will read in this tutorial. Firstly we will check constructors which are available to us to create an object of Date. Date() Date(milliseconds) Date(dateString) Date(year, month, day, hours, minutes, seconds, milliseconds) Methods of Date:  There is great collection of methods available in Date Object. Check the following table. Method Description getDate() This method would return current according to local time. getDay() It returns the integer value between 0 and 6 that represents the day of the week on the basis of local time. getFullYears() It returns the integer value that represents the year on the basis of local time. getHours() It returns the integer value between 0 and 23 that represents the hours on the basis of local time. getMilliseconds() It returns the integer value between 0 and 999 that represents the milliseconds on the basis of local time. getMinutes() It returns the integer value between 0 and 59 that represents the minutes on the basis of local time. getMonth() It returns the integer value between 0 and 11 that represents the month on the basis of local time. getSeconds() It returns the integer value between 0 and 60 that represents the seconds on the basis of local time. setDate() It sets the day value for the specified date on the basis of local time. setDay() It sets the particular day of the week on the basis of local time. setFullYears() It sets the year value for the specified date on the basis of local time. setHours() It sets the hour value for the specified date on the basis of local time. setMilliseconds() It sets the millisecond value for the specified date on the basis of local time. setMinutes() It sets the minute value for the specified date on the basis of local time. setMonth() It sets the month value for the specified date on the basis of local time. setSeconds() It sets the second value for the specified date on the basis of local time. 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

Date in JavaScript Read More »

String in JavaScript

In this tutorial, we will learn about String in JavaScript. In Strings are normally defined as a sequence of character. For example “Owlbuddy” Yes you can say “Owlbuddy” is a String in the programming language. There are two ways to define String in JavaScript: Using String literal Using String object Now we will check each way to create and we will try to understand it with the help of examples. Using String literal: In this method, we directly write var keyword and then literal for string and then we write a string in double quotes(” “). Follow this example to get a clear idea about this method. <script> var str=”Welcome To Owlbuddy”; document.write(str); </script> Using String object:  In this method, we create String object using new keyword and then we pass a string in Object. Check the following example. <script> var str=new String(“Welcome to Owlbuddy.”); document.write(str); </script> Basic string Methods: Here we will check some basic string Methods. That will help you so much while working with Strings Method Description charAt() It is use to check char at particular index. concat() It is use to concat two strings. indexOf() It is use to find index of character in String. lastIndexOf() It is use to find lat index of character n string. search() It is use to search regular expression from string. replace() It is use to replace part of string with some other char squence substr() It is use to get sub string from big string. toLowerCase() It converts whole string into lower case letters. toUpperCase() It converts whole string into upper case letters. toString() It return string form an object. valueOf() Provide primitive value of String object. 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

String in JavaScript Read More »

Array in JavaScript

In this tutorial, we will learn about Array in JavaScript. If you ever learn any other programming language then you would have a clear idea about Array. For those who are listening to this word for the very first time. The array is a collection of similar type of data elements. We use a single literal to fetch or add data in Array. There are three ways to define an array in JavaScript. Using Array literal Using a new keyword Using Array constructor We will understand each method to create Array with help of example. Using Array literal: In this method we directly define literal we define all elements of an array in square brackets. Mean we define and initialize the array together. As shown in Example. <script> var students=[“Raj”,”Sanjeev”,”Kishore”]; for (num=0;num<students.length;num++){ document.write(students[num] + ” “); } </script> Using square brackets: In this method we directly define literal we define all elements of an array in square brackets. Mean we define and initialize the array together. As shown in Example. <script> var students=[“Raj”,”Sanjeev”,”Kishore”]; for (num=0;num<students.length;num++){ document.write(students[num] + ” “); } </script> Using new keyword: in this method, we create array using the new keyword. Then we assign a value on different indexes of array. Following example will help you to understand it clearly. <script> var num; var students = new Array(); students[0] = “Raj”; students[1] = “Sanjeev”; students[2] = “Kishore”; for (num=0;num<students.length;num++){ document.write(students[num] + ” “); } </script> Using Array constructor: In this method, we pass values in Array Constructor while instantiating Array. Check the following example. <script> var students=new Array(“Raj”,”Sanjeev”,”Kishore”); for (num=0;num<students.length;num++){ document.write(students[num] + ” “); } </script>   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

Array in JavaScript Read More »

Objects in JavaScript

In this tutorial, we will learn about Objects in JavaScript. JavaScript is an Object-Oriented based language. Because programmers can perform basic oops concepts in code while working in JavaScript. But there is some difference as compared to other object-oriented programming languages. Because in JavaScript we don’t create classes. Because we create objects directly. it means you can say its template-based language not class-based. We will learn several things in this tutorial. Creating objects in JavaScript Defining method Object Object Method Creating an Object: To use Object, we need to create an object first so create an object we have three methods by using these we can create an object. These methods are as follow: Object literal Creating an object directly with the help of a new keyword. Using constructor Now we will check each in detail: Object literal: To create an object using object literal we just need to write object name then we have to define all properties using property name followed by the value. Follow this example to understand it more clearly. <script> car={color:”Red”,fuel:”Petrol”,type:”SUV”} document.write(car.color+” “+car.fuel+” “+car.type); </script> Creating an object directly with the help of a new keyword: In the last example, we learnt how we can create the object directly. Here we will create an object using the new keyword. Follow this example to understand it. <script> var car=new Object(); car.color=”Red”; car.fuel=”Petrol”; car.type=”SUV”; document.write(car.color+” “+car.fuel+” “+car.type); </script> Using constructor: In this type first we create function. Then we define all the properties of an object in that function. To understand it more clearly follow this example. <script> function car(color,fuel,type){ this.color=color; this.fuel=fuel; this.type=type; } myCar=new car(“Red”,”Petrol”,”SUV”); document.write(myCar.color+” “+myCar.fuel+” “+myCar.type); </script> Defining method in Object: We can easily create a function in our JavaScript Object. Just check the following example to understand it more wisely. <script> function student(id,name,fee){ this.id=id; this.name=name; this.fee=fee; this.feeSubmit=feeSubmit; function feeSubmit(submitAmount){ this.fee=this.fee-submitAmount; } } stu1=new student(10,”Ravi Shankar”,15000); document.write(stu1.id+” “+stu1.name+” “+stu1.fee); e.feeSubmit(10000); document.write(“<br>”+stu1.id+” “+stu1.name+” “+stu1.fee); </script> Object Method: There are several methods for objects. List of these methods is as follow: Methods Description Object.assign() This method id use to copy properties from source object to target object. Object.create() This method use to create Object in JavaScript. Object.defineProperty() This method id use to define property in Object Object.defineProperties() This method is used to create or configure multiple object properties. Object.is() This method is use to check two values are same or not. 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

Objects in JavaScript Read More »

Scroll to Top
×