Sunday, 11 June 2023

Advance Php-Part 1

 Q1) Attempt any Eight of the following. [8×2=16]

 

1.What is the use of abstract class?

·  An abstract class is a class that contains at least one abstract method.

·  An abstract method is a method that is declared, but not implemented in the code.

·  An abstract class or method is defined with the abstract keyword. An abstract class is a class that cannot be instantiated.

·  Typically, an abstract defines an interface for other classes to extend.

·  An abstract class is used to extend a class that  imports public, private, protected, and abstract methods.

·  Every abstract methods defined in the abstract class must be implemented inside the extended class. This is useful when we need to define a common structure between different classes.

 

2.What is the $_Server variable?

$_SERVER is a PHP super global variable which holds information about headers, paths, and script locations

<?php
echo $_SERVER['PHP_SELF'];
echo "<br>";
echo $_SERVER['SERVER_NAME'];
echo "<br>";
echo $_SERVER['HTTP_HOST'];
echo "<br>";
echo $_SERVER['HTTP_REFERER'];
echo "<br>";
echo $_SERVER['HTTP_USER_AGENT'];
echo "<br>";
echo $_SERVER['SCRIPT_NAME'];
?>

 

 

3.Enlist XML element.

 

XML elements can be defined as building blocks of an XML. Elements can behave as containers to hold text, elements, attributes, media objects or all of these.

Syntax

Following is the syntax to write an XML element –

<element-name attribute1 attribute2>

....content

</element-name>

 

where,

·         element-name is the name of the element. The name its case in the start and end tags must match.

·         attribute1, attribute2 are attributes of the element separated by white spaces. An attribute defines a property of the element.

 

 

3.What are different technologies are used in Ajax?

Ajax is not a technology but group of inter-related technologies. 

AJAX technologies includes:

  • HTML/XHTML and CSS
  • DOM
  • XML or JSON
  • XMLHttpRequest
  • JavaScript

HTML/XHTML and CSS

These technologies are used for displaying content and style. It is mainly used for presentation.

DOM

It is used for dynamic display and interaction with data.

XML or JSON

For carrying data to and from server. JSON (Javascript Object Notation) is like XML but short and faster than XML.

XMLHttpRequest

For asynchronous communication between client and server. For more visit next page.

JavaScript

It is used to bring above technologies together. Independently, it is used mainly for client-side validation.

4.What is Web Service?

A Web Service is can be defined by following ways:

  • It is a client-server application or application component for communication.
  • The method of communication between two devices over the network.
  • It is a software system for the interoperable machine to machine communication.
  • It is a collection of standards or protocols for exchanging information between two devices or application.
  • Web services are XML-based information exchange systems that use the Internet for direct application-to-application interaction. These systems can include programs, objects, messages, or documents.

5.What is content Management system.

 

·        A Content Management System is a software application used to create and design the web content online. It allows the users to manage the digital content easily by providing access to features like database handling, smart reporting, archiving, designing and animation features etc.

·        A content management system (CMS) is a software application that enables users to create, edit, collaborate on, publish and store digital content. CMS stands for Content Management System.

·        CMS is computer software used to edit, create, modify and publish digital content. Earlier, CMS software was used to manage computer documents and file, but now it is designed to help in managing the content of the web pages.

 

      6. Define UDDI

     UDDI is an XML-based standard for describing, publishing, and finding

     web   services.

·         UDDI stands for Universal Description, Discovery, and Integration.

·         UDDI is a specification for a distributed registry of web services.

·         UDDI is a platform-independent, open framework.

·         UDDI can communicate via SOAP, CORBA, Java RMI Protocol.

  7.What is PHP frame work.

 

·        A PHP framework is built on the open-source language PHP and offers built-in features to improve your software development lifecycle.

·        These features increase development speed and improve performance within your team by lowering the workload of your developers.

·        PHP has been around for many years, and as a result, it is extremely robust.

·        A PHP framework is a platform which allows a web developer to develop the web application.

 

·        In simple words, it provides a structure to develop web application.

 

     8. Define Template of object oriented

 

In PHP, templates are commonly used to create reusable layouts and to generate HTML content dynamically based on user input or other dynamic data. At a high level, templates in PHP allow you to define a layout or structure for your web pages and then fill in the content dynamically using PHP code.

 

9.State the purpose of Extend Keyword.

The extends keyword is used to derive a class from another class. This is called inheritance. A derived class has all of the public and protected properties of the class that it is derived from.

<?php
class MyClass {
  public function hello() {
    echo "Hello World!";
  }
}
class AnotherClass extends MyClass {
}

$obj = new AnotherClass();
$obj->hello();
?>

 

10.What is Class?

 

A class is defined by using the class keyword, followed by the name of the class and a pair of curly braces ({}).A class is a template for objects, and an object is an instance of class.

  • The class name should start with an alphabet.
  • The class name should not be a reserved PHP keyword.
  • The class name should not contain any spaces.

  11.What is $_ REQUEST variable?

 

PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form. 

 

<html>
<body>

<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
  Name: <input type="text" name="fname">
  <input type="submit">
</form>

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  // collect value of input field
  $name = $_REQUEST['fname'];
  if (empty($name)) {
    echo "Name is empty";
  } else {
    echo $name;
  }
}
?>

</body>
</html>

 

 

12.What is Serialization?

 

The serialize() function converts a storable representation of a value. To serialize data means to convert a value to a sequence of bits, so that it can be stored in a file, a memory buffer, or transmitted across a network.

<html>

<body>

 

<?php

$data = serialize(array("Red", "Green", "Blue"));

echo $data;

?>

 

</body>

</html>

serialize() returns a string containing a byte-stream representation of any value that can be stored in PHP. unserialize() can use this string to recreate the original variable values.

 

13.What is Document object Model in PHP?

The Document Object Model (DOM) is a programming API for HTML and XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated.

 

1.     DOMNode::appendChild() - Adds new child at the end of the children.

2.     DOMDocument::createAttribute() - Create new attribute.

3.     DOMDocument::createAttributeNS() - Create new attribute node with an associated namespace.

4.     DOMDocument::createCDATASection() - Create new cdata node.

 

        14.Describe any two content management system software.

·         WordPress Development

WordPress is the most popular free open source blogging tool as well as a content management system based on PHP. It has become the standard for a website that’s both functional and pleasant to browse. WordPress is having wide variety of styles, design flexibility, reliable, secure and pleasant to work. It is one of the most user friendly CMS and it offers simple flow to integrate theme, widgets and plugins. WordPress users have the option to build a site of any context, eCommerce, business, community, healthcare, travel, creative, non-profit and so forth. SSTech System a pioneer PHP application development company, specializes in WordPress development and have created numerous stunning, user-friendly websites across all industry verticals.

WordPress is a popular target for hackers because of its high circulation, so users’ needs to update their WordPress software fairly regularly with security updates. These updates come out fast after security incidents and aren’t always compatible with all the extensions that are required for effective use of the software. Software updates can be associated with considerable administrative efforts, in case of large projects.

WordPress is good for small and simple structured websites, especially for bloggers, who want to provide their visitors with frequent changing content in attractive layouts.

If you are looking for a stable website operation, WordPress places a high demands on server comparatively as your visitor traffic increases. Users who want to develop complex multi-domain projects with a multi-lingual focus should choose a CMS.

·         Joomla Development

Joomla development is bit of a challenge at least in terms of coding power than WordPress. It is the second biggest agent in the CMS market with 2.5 million installation worldwide. It’s code base is much more sophisticated than that of WordPress.  Joomla is an open source content management system to build powerful websites and online template based application. Medium to large sized sites can be built with the help of Joomla framework. It offers themes and templates for user friendly actions.

Joomla divides extensions into plugins, components and modules. These can be used in the backend as well as the front end, which is sometimes irritating to users. Extensions are not always available for free.

People using Joomla are quite fond of features like native front-end content editing, content management flexibility, and a native integration of multiple languages which makes the sites content more friendly towards visitors of foreign nature.

·         Drupal

Drupal is an open source content management system which is distributed under the general public license. It is generally use to build very flexible eCommerce websites and web based applications.

Drupal comes with an extremely lean basic installation, that can be extended quite a bit by modules. It offers extensive opportunities for customization with its modular layout. Drupal is suited for small and medium sized projects. The large spectrum of extensions makes it feasible to implement company portals with complex multi-domain structures. The administration of a CMS core with extensions requires expertise and instinct. If the basic functions of the software are not sufficient, then additional modules will have to be installed manually via FTP. It can be a complex process. Updating extensions is at times difficult, as these are not always compatible with the backend. The CMS boasts a flexible, modular system for dynamic platforms based on user generated content.

Drupal has been accepted as a primary content management platform by a lot of engineer and developer as it goes even deeper into the architecture of the content management system itself, and it is widely adapted to professional coding standards. It offers more than 30,000+ extendable modules to take your site to a whole new level, as well as 2,000+ individual and unique themes that will help to build the site that you’ve always wanted to build. It is use to build very flexible eCommerce websites and web applications.

·         Magento

Magento is the best choice to opt for an independent eCommerce platform altogether, whether it is for a small business solution in an environment where nobody really understand technology

 

15.State the purpose of Final Keyword?

 

  • In PHP, Final keyword is applicable to only class and class methods. We cannot declare as Final in PHP.
  • So if we declare class method as a Final then that method cannot be override by the child class.
  • Same as method if we declare class as a Final then that class cannot be extended any more.

Example 1

<?php  

      

    class base  

    {  

        final public function dis1()  

        {  

            echo "Base class..";  

        }     

    }  

    class derived extends base  

    {  

        public function dis1()  

        {  

            echo "derived class";  

        }  

    }  

    $obj = new derived();  

    $obj->dis1();  

  

?>  

 

16.What is meaning of Self Processing form?

PHP self-processing form. Sometimes, you want to include both form and logic for handling form submission in a single PHP file. This form is often referred to as a self-processing form. To create a self-processing form, you can use the $_SERVER['REQUEST_METHOD'] that returns the request method e.g., GET or POST .

$_SERVER[‘PHP_SELF’]: The $_SERVER[“PHP_SELF”] is a super global variable that returns the filename of the currently executing script. It sends the submitted form data to the same page, instead of jumping on a different page.

 

17.What is AJAX Script?

 

AJAX = Asynchronous JavaScript and XML.

AJAX is a technique for creating fast and dynamic web pages.

AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.

Classic web pages, (which do not use AJAX) must reload the entire page if the content should change.

Examples of applications using AJAX: Google Maps, Gmail, Youtube, and Facebook tabs.

18. What is Introspection ?

 

Introspection is the ability of a program to examine an object's characteristics, such as its name, parent class (if any), properties, and methods.

 

Function

Description

class_exists()

Checks whether a class has been defined.

et_class()

Returns the class name of an object.

get parent_class()

Returns the class name of a Return object's parent class.

is_subclass_of()

Checks whether an object has a given parent class.

get_declared_classes() 

Returns a list of all declared classes.

get_class_methods() 

Returns the names of the class methods.

get_class_vars()

Returns the default properties of a class

interface_exists()

Checks whether the interface is defined.

method_exists()

Checks whether an object defines a method.

 

19. What is Inheritance ?

 

·        It is a concept of accessing the features of one class from another class. If we inherit the class features into another class, we can access both class properties. We can extends the features of a class by using 'extends' keyword.

·        It supports the concept of hierarchical classification.

·        Inheritance has three types, single, multiple and multilevel Inheritance.

·        PHP supports only single inheritance, where only one class can be derived from single parent class.

·        We can simulate multiple inheritance by using interfaces.

<?php  

class a  

    {  

        function fun1()  

        {  

            echo "javatpoint";  

        }  

    }  

    class b extends a  

    {  

        function fun2()  

        {  

            echo "SSSIT";  

        }  

    }  

    $obj= new b();  

    $obj->fun1();  

?>  

 

20.What is  Interfaces ?

 

·        An interface is similar to a class except that it cannot contain code.

·        An interface can define method names and arguments, but not the contents of the methods.

·        Any classes implementing an interface must implement all methods defined by the interface.

·        A class can implement multiple interfaces.

·        An interface is declared using the "interface" keyword.

·        Interfaces can't maintain Non-abstract methods.

<?php  

    interface a  

    {  

        public function dis1();  

    }  

    interface b  

    {  

        public function dis2();  

    }  

  

class demo implements a,b  

{  

    public function dis1()  

    {  

        echo "method 1...";  

    }  

    public function dis2()  

    {  

        echo "method2...";  

    }  

}  

$objnew demo();  

$obj->dis1();  

$obj->dis2();  

  

?>  

 

21. What is Encapsulation ?

 

 

Encapsulation is a concept where we encapsulate all the data and member functions together to form an object.

Wrapping up data member and method together into a single unit is called Encapsulation.

Encapsulation also allows a class to change its internal implementation without hurting the overall functioning of the system.

 

Binding the data with the code that manipulates it.

 

It keeps the data and the code safe from external interference.

<?php  

class person  

{  

public $name;  

public $age;  

function __construct($n, $a)  

{  

$this->name=$n;  

$this->age=$a;  

}  

public function setAge($ag)  

 {  

   

$this->ag=$ag;  

   

}  

   

public function display()  

   

{  

   

echo  "welcome ".$this->name."<br/>";  

   

return $this->age-$this->ag;  

   

}  

   

}  

   

$person=new person("sonoo",28);  

   

$person->setAge(1);  

   

echo "You are ".$person->display()." years old";  

   

?>