We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7
1.
How to create object in php
<?php // Define a simple class class MyClass { public $myVariable; public function __construct($value) { $this->myVariable = $value; } public function display() { echo "Value of myVariable is: " . $this->myVariable; } } // Create an object of MyClass $obj = new MyClass("Hello, world!"); // Call a method of the object $obj->display(); ?> 2. What is abstract class write characteristics of abstract class An abstract class in PHP is a class that cannot be instantiated directly. It is meant to be a base class for other classes and provides a blueprint for the methods and properties that its subclasses must implement. Abstract classes are declared using the abstract keyword. Here are the characteristics of an abstract class in PHP: ~ Cannot be instantiated directly: Abstract classes cannot be used to create objects. They are meant to be extended by other classes. ~ Can have abstract methods: Abstract classes can contain abstract methods, which are methods without a body. These methods must be implemented by any concrete subclass. ~ Can have non-abstract methods: Abstract classes can also have non-abstract methods, which have a body and can be inherited by subclasses. ~ Can have abstract properties: Abstract classes can have abstract properties, which are properties without a value. These properties must be implemented by any concrete subclass. 3. What is serialization? Serialization in PHP refers to the process of converting a PHP data structure (such as an array or an object) into a format that can be stored or transmitted and later reconstructed to its original form. This is typically used when you need to store data in a file or database, or when you need to send data over a network. The serialized data is typically represented as a string, which can then be stored in a file, database, or transmitted over a network. The serialized data can later be deserialized, or converted back into its original PHP data structure. 4. What is interface explain with example An interface in PHP is a contract that defines a set of methods that a class must implement. It provides a way to define the structure of a class without actually implementing any of its methods. Interfaces are declared using the interface keyword. <?php interface Animal { public function makeSound(); } class Dog implements Animal { public function makeSound() { return "Woof!"; } } $dog = new Dog(); echo $dog->makeSound(); // Output: Woof! ?> 5. Explain different parameters use for $_SERVER information The $_SERVER superglobal in PHP is an associative array containing information about the server environment, such as the server's software and configuration, the client's browser and IP address, and more. It is a powerful tool for gathering information about the server and the request that a PHP script is handling. $_SERVER['HTTP_HOST']: This parameter contains the hostname of the server that is handling the current request. $_SERVER['REQUEST_METHOD']: This parameter contains the request method (e.g., GET, POST, etc.) used by the client to make the current request. $_SERVER['REQUEST_URI']: This parameter contains the URI (Uniform Resource Identifier) of the current request. $_SERVER['QUERY_STRING']: This parameter contains the query string portion of the URI of the current request. 6. What is sicky form? Explain A "sticky form" in PHP refers to a web form that retains the values entered by the user even after the form has been submitted. This is often used to provide a better user experience by allowing the user to correct any errors in the form without having to re- enter all the information. 7. What is self-processing form A "self-processing" form in PHP is a form where the form submission and processing logic are contained within the same PHP script. In other words, the form's action attribute points to the same PHP script that renders the form, handles the form submission, validates input, and processes the form data. ~ Form Display: The PHP script initially displays the HTML form to the user. ~ Form Submission: When the user submits the form, the same PHP script handles the form submission by checking the request method ($_SERVER["REQUEST_METHOD"]) to determine if the form has been submitted via POST. ~ Form Processing: If the form has been submitted, the PHP script processes the form data, performs any necessary validation, and executes any business logic required for the application. ~ Redisplay Form with Errors: If there are validation errors or processing issues, the PHP script redisplay the form with error messages and, possibly, previously submitted values (making it a sticky form) to allow the user to correct any mistakes. 8. Difference between $_get and $_post variables ~Data Transmission Method: $_GET: Data is transmitted in the URL as query parameters. This means that the form data is visible in the URL and can be bookmarked or shared. $_POST: Data is transmitted in the HTTP request body. This means that the form data is not visible in the URL and is not bookmarkable or shareable. ~Data Size Limit: $_GET: Limited by the maximum length of a URL (typically around 2048 characters, but this can vary depending on the browser and server settings). $_POST: Limited by the server's configuration (e.g., post_max_size and upload_max_filesize settings in the php.ini file). ~Security: $_GET: Less secure because the data is visible in the URL and can be tampered with by the user. $_POST: More secure because the data is not visible in the URL and is transmitted in the request body. ~Usage: $_GET: Typically used for requests that do not change the server state (e.g., search queries, pagination, etc.). $_POST: Typically used for requests that change the server state (e.g., form submissions, data updates, etc.). 9. Explain concept of the XML XML (eXtensible Markup Language) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. It is widely used for representing structured data in a hierarchical format. In PHP, you can work with XML in various ways, such as parsing XML documents, creating XML documents, and transforming XML documents using XSLT. ~ XML Parsing: PHP provides several functions for parsing XML documents, such as simplexml_load_string(), simplexml_load_file(), and xml_parse(). ~ XML Generation: PHP provides functions for generating XML documents, such as simplexml_load_string(), simplexml_load_file(), and xml_parse(). ~ XML Validation: PHP provides functions for validating XML documents against a schema, such as libxml_use_internal_errors(), libxml_get_errors(), and libxml_clear_errors(). ~ XPath: XPath is a language for addressing parts of an XML document. PHP provides functions for querying XML documents using XPath, such as DOMXPath::query(). 10. What is XML parser what are different type explain with example An XML parser is a software component or library that reads XML documents and interprets their structure, allowing developers to extract information and manipulate data within the document. XML parsers come in different types, each with its own approach to parsing and processing XML documents. Here are the main types of XML parsers: DOM Parser (Document Object Model): ~ DOM parsers create a tree-like representation of the entire XML document in memory, where each node in the tree corresponds to an element, attribute, text node, etc. ~ DOM parsers provide a powerful API for navigating and manipulating the XML document using methods such as getElementById(), getElementsByTagName(), and createElement(). SAX Parser (Simple API for XML): ~ SAX parsers parse XML documents sequentially and generate events as they encounter elements, attributes, text, etc. ~ SAX parsers do not build a complete in-memory representation of the XML document, making them memory-efficient and suitable for large XML documents. 11. Write php program to create class temperature which contains data members as Celsius and Fahrenheit. Define parameterized constructor in Celsius <?php class Temperature { private $celsius; private $fahrenheit; // Parameterized constructor to initialize Celsius temperature public function __construct($celsius) { $this->celsius = $celsius; $this->fahrenheit = $this->convertToCelsiusToFahrenheit($celsius); } // Method to convert Celsius to Fahrenheit private function convertToCelsiusToFahrenheit($celsius) { return ($celsius * 9/5) + 32; } // Method to get Celsius temperature public function getCelsius() { return $this->celsius; } // Method to get Fahrenheit temperature public function getFahrenheit() { return $this->fahrenheit; } } // Create an object of Temperature class with Celsius temperature as 20 $temperature = new Temperature(20); // Get and display Celsius and Fahrenheit temperatures echo "Celsius temperature: " . $temperature->getCelsius() . "°C<br>"; echo "Fahrenheit temperature: " . $temperature->getFahrenheit() . "°F"; ?> 12. Write php script to create cd catlog using xml file Xml file - <?xml version='1.0' encoding='UTF-8' ?> <CD> <cd type='music'> <name>silent_songs</name> <launch-date>5-6-2014</launch-date> <composer>A-R-Rehman</composer> </cd> <cd type='music'> <name>Hip-Hop</name> <launch-date>4-8-2011 </launch-date> <composer>Yo-Yo-Honey singh </composer> </cd> <cd type='music'> <name>love track </name> <launch-date>6-9-2000</launch-date> <composer>Arjit Singh</composer> </cd> </CD> Php file - <?php $xml=simplexml_load_file('slip_11_Q3.xml'); var_dump($xml); ?>