Tutorial for Inheritance in OOPS

what is Inheritance?

In OOP, the concept of inheritance allows a class to accept or have the properties of another class (inherited). A sub-class or derived class is a class that inherits the characteristics/methods of another class. Heritage reduces code redundancy, allowing the class to use other class methods without having to rewrite the code. This allows for dynamic programming using the main class’s methods (also called the parent class). A subclass has the same properties as a primary class, but it can also have additional methods that are either completely independent or not present in the main class.

What is the Function of Inheritance?

Children’s classes may be built to enhance the parent’s class functionality and add more characteristics once essential properties and behaviors have been defined in the parent’s class.

Example:-

This distinction is demonstrated by creating a parent class child class(HerdingDog) (Dog) and then adding a single herd() behaviour.

The following code shows how the child class (HerdingDog) inherits a parent class method (bark) (Dog), and the child class adds an extra method herd().

When the code uses the fluffy.bark() function, the method bark() travels up the child’s chain to find out where the bark method is declared.

Tagged : / / / / / / /

Tutorial for Object-oriented programming (OOP) Concept

Computer programming skills is in high demand in today’s technology culture for programming. Understanding object-oriented programming may be useful in the creation and management of software systems (OOP). This article covers the core concepts of OOP and illustrates them with simple examples.

What is Object-oriented programming (OOP)?

Object Oriented Programming: A curated set of resources

Object-oriented programming is the process of integrating variables (properties) and functions (methods) into a single object. These products are organized into classes that may be mixed and matched. OOP allows you to think about the objects in a program’s code as well as the various actions that go along with them.

What are the principles of Object-oriented programming (OOP)?

What are four basic principles of Object Oriented Programming? | by Munish  Chandel | Medium

Encapsulation, Abstraction, Inheritance, and Polymorphism are the four basic concepts of object-oriented programming. Although these concepts appear to be extremely complicated, understanding the broad framework of how they work is beneficial. The four basic hypotheses are as follows:

  1. Inheritance: child classes inherit data and behaviors from parent class
  2. Encapsulation: containing information in an object, exposing only selected information
  3. Abstraction: only exposing high level public methods for accessing an object
  4. Polymorphism: many methods can do the same task

Tagged : / / / / / / / / / /

Tutorial for $_GET in Super Global Variables

What is $_GET?

$_GET is a global variable that is used to collect data from an HTML form after it has been submitted. The data is visible in the query string when the form uses method get to transmit data, thus the values are not concealed. The values in the URL are stored in the $_GET super global array variable.

Web Development Course: PHP lecture 1

Example:-

Output:-

Right now, we’re just seeing half of the rationale. We’ve generated a linked image of Nainital Lake in the preceding code, which will take us to the picture.php page and provide the parameters name=”Nainilake” and city=”Nainital” to it.

That is, if we click on the little image of Nainital Lake, we will be brought to the next page picture.php, where the parameters will be displayed. These arguments will be given to the next page using the get method, and they will be shown in the address bar, as get is the default way. When we wish to transmit data to an address, we use a question mark (?) to connect them to the address.

The address has the name=Nainilake parameter connected to it. If we wish to add more values, we may do so by appending an ampersand (&) after each key-value combination, similar to how city=Nainital is appended after the name parameter. Now, when you click on the image of Nainital Lake, we want the picture.php page to appear, along with the value of the parameter.

$_POST vs $_GET

PHP Variables and scopes
Tagged : / / / / / / / / /

Tutorial for $_POST in Super Global Variables

What is $_POST?

It’s a global variable that’s used to collect data from the HTML form after it’s been submitted. Because the data is not accessible in the query string when a form uses method post to transfer data, security standards are maintained in this manner.

Example:- A form with an input field and a submit button is shown in the example below. The form data is delivered to the file provided in the action element of the form> tag when a user submits the data by clicking “Submit.” For processing form data, we point to the file itself in this case. Replace it with the filename of your choosing if you want to process form data with another PHP file. The value of the input field may then be collected using the super global variable $_POST:

Output:-

Before filling Data.
Just filling some data
After clicking on Submit button

We have developed a form in the preceding code that accepts the user’s name and age and accesses the data using the $_POST super global variable when they submit the data. Each super global variable is an array, thus it may hold many values. As a result, we took the $_POST variable’s name and age and placed them in the $nm and $age variables. We have developed a form in the preceding code that accepts the user’s name and age and accesses the data using the $_POST super global variable when they submit the data. Each super global variable is an array, thus it may hold many values. As a result, we took the $_POST variable’s name and age and placed them in the $nm and $age variables.

Tagged : / / / / / / / / / /

Tutorial for $_REQUEST in Super Global Variables

What is $_REQUEST?

$_REQUEST is a super global variable that’s used to collect data when an HTML form is submitted. Because $_POST and $_GET accomplish the same purpose and are extensively used, $_REQUEST is rarely used.

Global Variables - Superglobals Several predefined variables in PHP are  "superglobals", which means that they are always accessible, regardless of  scope. - ppt download

Example:- A form with an input field and a submit button is shown in the example below. The form data is delivered to the file provided in the action element of the form> tag when a user submits the data by clicking “Submit.” For processing form data, we point to this file in our example. Replace it with the filename of your choosing if you want to process form data with another PHP file. The value of the input field may then be collected using the super global variable $_REQUEST:

Output:-

Empty box
Just fill some data
After Clicking on submit button it shows this result

We’ve constructed a form in the above code that accepts the user’s name as input and prints it when the submit button is pressed. Because we alter the data on the same page using PHP code, we transfer the data received in the form to the same page using the $_SERVER[‘PHP SELF’] element as stated in the action attribute. The $_REQUEST super global array variable is used to obtain the data.

Tagged : / / / / / / / / / /

Tutorial for $_SERVER in Super Global Variables

What is $_SERVER?

It’s a super global variable in PHP that keeps track of headers, paths, and script locations. Some of these components are used to obtain data from the $_SERVER super global variables.

Server IP (PHP $_SERVER variables) | Drupal.org

Example:-

Output:-

To retrieve some information, we used the $_SERVER components in the code above. Using the ‘PHP SELF’ element, we retrieve the current file name that is being worked on. Then, using the ‘SERVER NAME’ attribute, we retrieve the current server name. Then we use ‘HTTP HOST’ to retrieve the host name.

The following table lists the most important elements that can go inside $_SERVER:

Element/CodeDescription
$_SERVER[‘PHP_SELF’]Returns the filename of the currently executing script
$_SERVER[‘GATEWAY_INTERFACE’]Returns the version of the Common Gateway Interface (CGI) the server is using
$_SERVER[‘SERVER_ADDR’]Returns the IP address of the host server
$_SERVER[‘SERVER_NAME’]Returns the name of the host server (such as www.w3schools.com)
$_SERVER[‘SERVER_SOFTWARE’]Returns the server identification string (such as Apache/2.2.24)
$_SERVER[‘SERVER_PROTOCOL’]Returns the name and revision of the information protocol (such as HTTP/1.1)
$_SERVER[‘REQUEST_METHOD’]Returns the request method used to access the page (such as POST)
$_SERVER[‘REQUEST_TIME’]Returns the timestamp of the start of the request (such as 1377687496)
$_SERVER[‘QUERY_STRING’]Returns the query string if the page is accessed via a query string
$_SERVER[‘HTTP_ACCEPT’]Returns the Accept header from the current request
$_SERVER[‘HTTP_ACCEPT_CHARSET’]Returns the Accept_Charset header from the current request (such as utf-8,ISO-8859-1)
$_SERVER[‘HTTP_HOST’]Returns the Host header from the current request
$_SERVER[‘HTTP_REFERER’]Returns the complete URL of the current page (not reliable because not all user-agents support it)
$_SERVER[‘HTTPS’]Is the script queried through a secure HTTP protocol
$_SERVER[‘REMOTE_ADDR’]Returns the IP address from where the user is viewing the current page
$_SERVER[‘REMOTE_HOST’]Returns the Host name from where the user is viewing the current page
$_SERVER[‘REMOTE_PORT’]Returns the port being used on the user’s machine to communicate with the web server
$_SERVER[‘SCRIPT_FILENAME’]Returns the absolute pathname of the currently executing script
$_SERVER[‘SERVER_ADMIN’]Returns the value given to the SERVER_ADMIN directive in the web server configuration file (if your script runs on a virtual host, it will be the value defined for that virtual host) (such as someone@w3schools.com)
$_SERVER[‘SERVER_PORT’]Returns the port on the server machine being used by the web server for communication (such as 80)
$_SERVER[‘SERVER_SIGNATURE’]Returns the server version and virtual host name which are added to server-generated pages
$_SERVER[‘PATH_TRANSLATED’]Returns the file system based path to the current script
$_SERVER[‘SCRIPT_NAME’]Returns the path of the current script
$_SERVER[‘SCRIPT_URI’]Returns the URI of the current page
Tagged : / / / / / / / / / /

Tutorial for $GLOBALS in Super Global Variables

What is $GLOBALS?

$GLOBALS is a super global variable that may be accessed from anywhere in the PHP script. All global variables are stored in the array $GLOBALS[], where index is the global variable name that may be retrieved.

All global variables are stored in an array named $GLOBALS[index] in PHP. The variable’s name is stored in the index.

Global Variables - Superglobals Several predefined variables in PHP are  "superglobals", which means that they are always accessible, regardless of  scope. - ppt download

The example below shows how to use the super global variable $GLOBALS:

Example:-

Output:-

Two global variables, $x and $y, are declared in the above code and are given a value. Then, in the GLOBAL array, a function multiplication() is written to multiply the values of $x and $y and store the result in another variable $z.

Tagged : / / / / / / / / / /

Tutorial for Super Global Variables in PHP

What is Super Global Variables in PHP?

These are PHP array variables with specific definitions that make it simple to retrieve information about a request or its context. The super global variables may be found all across your script. These variables can be accessible from any function, class, or file without the need to do any further steps, such as defining a global variable. They are mostly employed in applications to save and retrieve data from one page to the next.

PHP Variables and scopes

The following are the PHP superglobal variables:

  • $GLOBALS
  • $_SERVER
  • $_REQUEST
  • $_POST
  • $_GET
  • $_FILES
  • $_ENV
  • $_COOKIE
  • $_SESSION
PHP 5 Global Variables - Superglobals - MEGATEK ICT ACADEMY
Tagged : / / / / / / /

Tutorial for fgets() in Reading file

What is fgets() used in Reading file?

This function is used to read a single line from a file. You can pass this function a file handle corresponding to an open file, and optional length.

Why fgets() used in Reading file?

  • It returns a line from a file pointer and terminates at a given length, end of file(EOF), or new line, whichever comes first.
  • The fgets() function is passed the file to read and the number of bytes to read as arguments, and it returns a string of length -1 bytes from the file indicated by the user.
  • If it fails, it returns False.

Syntax:-

fgets(file, length)
Parameters Used:
The fgets() function in PHP accepts two parameters.
file : It specifies the file from which characters have to be extracted. 
length : It specifies the number of bytes to be read by the fgets() function. The default value is 1024 bytes.

Return Value : It returns a string of length -1 bytes from the user-specified file, or False if the operation fails.

Errors And Exceptions:-

  • Because it reads a single line at a time, the method isn’t designed for huge files, and reading a long file can take a long time.
  • If the fgets() method is called more than once, the buffer must be emptied.
  • Although the fgets() method returns the Boolean False, it frequently produces a non-Boolean result that evaluates to False.

Let’s take one Example:-

Suppose there is a file named “test.txt” which consists of :

This is the first line.
This is the second line.
This is the third line.

Example 1:-

Output:

Example 2:-

Output:-

Tagged : / / / / / / /

Tutorial for Reading file on File Handling in PHP

What is Reading file on File Handling?

PHP has a number of functions for reading data from files. You may read entire file data, read data line by line, or read data character by character using various methods.

How many types of PHP file Read Functions are:-

The available PHP file read functions are given below.

  • fread()
  • fgets()
  • feof()

PHP readfile() Function

Reads a file and publishes it to the output buffer with the readfile() method.

Assume we have a text file on the server named “webdictionary.txt” that looks like this:

AJAX = Asynchronous JavaScript and XML
CSS = Cascading Style Sheets
HTML = Hyper Text Markup Language
PHP = PHP Hypertext Preprocessor
SQL = Structured Query Language
SVG = Scalable Vector Graphics
XML = EXtensible Markup Language

The following is the PHP code for reading the file and writing it to the output buffer (the readfile() method returns the number of bytes read if successful):

Example:-

If all you want to do is open a file and read its contents, the readfile() method comes in handy.

Tagged : / / / / / / / / / / / /