• What is PHP?
  • It is a popular choice for developing content management systems (CMS) like WordPress and e-commerce platforms like WooCommerce. Additionally, PHP can be used for command-line scripting and other server-side tasks.
  • What is a session in PHP?
  • In PHP, a session is a mechanism for preserving information that needs to be accessed across multiple pages within a website. Unlike cookies, this information is not stored on the user’s device. Instead, a file is created on the server in a temporary directory, where registered session variables and their values are kept. This data remains accessible to all pages on the website throughout the user’s visit.
  • Think of a session as analogous to working with an application: you open it, make changes, and then close it. During this process, the computer recognizes who you are, when you initiated and concluded the session.
  • However, on the internet, web servers are unaware of your identity or your activities because the HTTP protocol is stateless. To address this limitation, session variables are employed to save user information that must persist across various pages (e.g., username, favorite color, etc).
  • By default, session variables persist until the user closes their web browser. Consequently, session variables store individual user details and remain accessible across all pages within a single application
  • What is PEAR in PHP?
  • PEAR is an acronym for ‘PHP Extension and Application Repository.’ PEAR serves as both a framework and a repository for a broad spectrum of reusable PHP components. Within PEAR, web developers access an elevated level of programming resources. This repository houses diverse PHP code snippets and libraries, further offering a convenient command-line interface for the automated installation of packages
  • Explain the difference b/w static and dynamic websites.
Static WebsiteDynamic Website
In static websites, the content remains fixed and unalterable after the initial script execution.In dynamic websites, the script’s content can be modified at runtime.
Any modifications to the site are not possible; it’s predefined and static.Its content is regenerated each time a user visits or reloads the page. Websites like Google, Yahoo, and various search engines serve as prime examples of dynamic websites.
  • What are the popular Content Management Systems (CMS) in PHP?
  • There are many CMS that are made using PHP. The popular ones are as mentioned below:
    • WordPress: WordPress is a free and open-source content management system (CMS) that relies on PHP and MySQL. It features a plug-in system and a template framework. While it is commonly associated with blogging, WordPress supports a wide array of web content, including traditional mailing lists, forums, media displays, and e-commerce.
    • Joomla: Joomla is another free and open-source CMS for content management. It is developed by Open Source Matters, Inc. Joomla is built on a model-view-controller web application framework, offering flexibility and the option to use it independently of the CMS.
    • Magento: Magento is an open-source e-commerce platform developed by Varien Inc. It is a powerful tool for online businesses, thanks to its flexible modular architecture and extensive control options that cater to the needs of users. Magento employs an e-commerce framework, providing comprehensive e-commerce solutions and a strong support community.
    • Drupal: Drupal is a PHP-based CMS platform distributed under the GNU General Public License.
  • What are the popular frameworks in PHP?
  • Popular frameworks of PHP are:
    • CakePHP
    • CodeIgniter
    • Yii 2
    • Symfony
    • Zend Framework etc.
  • What is the difference between “echo” and “print” in PHP?
EchoPrint
PHP’s echo outputs one or more strings.PHP’s print is used to output a string.
It’s considered a language construct rather than a function, so it doesn’t require parentheses for outputting a single string, However, when you need to pass more than one parameter to echo, using parentheses becomes necessary.It functions as a language construct, not a function, and therefore doesn’t necessitate parentheses for the argument list.
Echo is faster than print because it does not return any valueUnlike echo, print always returns a value of 1.
  • What is the difference between $message and $$message?
$message$$message
$message is used to store data in a variable.$$message is employed to store variables as variables themselves.
$message contains static data.$$message can be modified dynamically.
  • How many data types or variable types are there in PHP?
  • PHP data types are utilized for containing various data or values. PHP classifies its 8 primitive data types into three categories:
    • Scalar Types (predefined): These types store a single value, and there are 4 scalar data types in PHP:
      • Boolean: It represents two logical states- true or false.
      • Integer: Integers are whole numbers without a floating-point.
      • Float/Double: Doubles are floating-point numbers. Eg: 1.123.
      • String: Strings are a sequence of characters.
    • Compound Types (user-defined): These types can hold multiple values, and there are 2 compound data types in PHP:
      • Array: Array is a named and ordered collection of similar type of data.
      • Object: An instance of classes containing data and functions.
    • Special Types: PHP includes 2 special data types:
      • Resource: Resources are special variables that consist of references to resources external to PHP(such as database connections).
      • Null: NULL is a special type that only has one value, NULL. When no value is assigned to a variable, it can be assigned with NULL.
  • What are the rules for naming a PHP variable?
    • In PHP, a variable is denoted by a dollar symbol followed by its name. For instance, $name = 100; assigns the value 100 to the variable named ‘price.’
    • Variables must commence with a letter or an underscore.
    • Variable names can comprise letters, numbers, or underscores, but not characters like +, -, %, &, etc.
    • Variable names cannot contain spaces.
    • PHP variables are case-sensitive, distinguishing between $NAME and $name as two distinct variables.”
  • How can PHP and HTML interact?
  • PHP scripts can generate HTML content, and they allow for the exchange of data from HTML to PHP. While PHP is a server-side language, HTML functions on the client-side. This means that PHP runs on the server, processing data and generating results in the form of strings, objects, and arrays. These results are then utilized to display values within the HTML. This interplay between PHP and HTML enables a synergistic relationship, harnessing the strengths of both languages.
  • Explain the importance of Parser in PHP?
  • A PHP parser is a software tool that translates source code into a format understandable by computers. This means that the set of instructions provided in PHP code is transformed into a machine-readable format by the parser. To parse PHP code within PHP itself, you can utilize the token_get_all() function.
  • What is the use of @ in PHP?
  • In PHP, the “@” symbol is used as an error control operator. It is placed in front of an expression, statement, or function call to suppress error messages and notices that would normally be displayed to the user. When “@” precedes a statement, PHP will not generate error messages or notices if that statement encounters an error.
    • $result = @file_get_contents(‘non_existent_file.txt’);

In this code, if ‘non_existent_file.txt’ is not found, PHP will typically generate an error or notice. However, when using the “@” symbol, the error message will be suppressed, and the value of $result will be false instead of an error message.

  • What are the different types of Array in PHP?
  • In PHP, there are three main types of arrays:
    • Indexed array: This type of array uses numeric keys.
    • Associative array: Each key in this array has a specific associated value.
    • Multidimensional array: This is an array that contains one or more arrays within itself.
  • Few main array functions in PHP are:
    • array()
    • array_change_key_case()
    • array_chunk()
    • count()
    • sort()
    • array_reverse()
    • array_search()
    • array_intersect()
  • What are traits?
  • Traits serve as a mechanism for creating reusable code in PHP and related languages, especially in scenarios where multiple inheritances are not supported. Traits cannot be instantiated independently.
  • The primary purpose of a trait is to overcome the constraints of single inheritance by allowing developers to freely reuse sets of methods across various classes that may reside in distinct class hierarchies.
  • Explain the main types of errors.
  • The three primary error types in PHP are as follows:
    • Notices: Notices are non-critical errors that can occur during script execution. They are not visible to users and may include issues like accessing an undefined variable.
    • Warnings: Warnings are more critical than notices but do not halt script execution by default. They are visible to the user and can result from actions such as attempting to include a non-existent file using include().
    • Fatal Errors: This is the most critical error type. When a fatal error occurs, it immediately terminates script execution. Examples include trying to access a property of a non-existent object or requiring a non-existent file using require().”
  • How JavaScript interacts with PHP?
  • JavaScript is a client-side programming language, while PHP is a server-side scripting language. PHP has the capability to create JavaScript variables, which can then be executed within the browser. This allows for the straightforward passing of variables to PHP via a simple URL.
  • What do you understand by “Path Traversal”?
  • Path traversal is a method for exploiting vulnerabilities within the targeted web file, often referred to as a ‘dot-dot-slash attack. Path traversal, also known as ‘Directory Traversal,’ is a type of attack aimed at accessing files within a web application. It utilizes the ‘../’ (dot-dot-sequences) symbol, which is cross-platform and signifies moving up in the directory structure. Path traversal leverages this symbol to navigate through web application files. An attacker can expose the contents of a targeted file by traversing paths outside the root directory of a web server or application. This is typically done to gain access to confidential passwords, tokens, and other sensitive information stored within files.
  • What is the meaning of ‘escaping to PHP’?
  • PHP escape is a method used to signal to the PHP parser that specific code elements should be treated differently from regular PHP code. It’s a way to distinguish a part of PHP code from the rest of the program.
  • Think of PHP escape as a way to tell PHP that something is not regular code.
  • What are sessions in PHP?
  • Sessions are like global storage on the server, and each session is labeled with a unique server ID. This ID helps manage the storage and retrieval of data.
  • What are cookies? How to create cookies in PHP?
  • Cookies are used to recognize individual users. They’re tiny files planted on the user’s device by the server. These files help the server gather information that’s useful for various aspects of its operation. We can create cookies using the setcookie() function, syntax for the same is:
  • setcookie(name, value, expire, path, domain, secure, httponly);
  • Here name is mandatory and the remaining parameters are optional.
  • Example: setcookie(“productname”, “productprice”)
  • Mention various important PHP String functions.
  • Few main string functions are:
    • strtolower() : to convert string in lowercase
    • strtoupper(): to convert string in uppercase
    • ucfirst(): Make the first character of the string to uppercase
    • lcfirst(): It is used to convert the first character of a string to lowercase.
    • ucwords(): Make the first character of each word in a string to uppercase
    • strrev(): It is used to reverse a string.
    • strlen(): It is used to return the length of a string.
    • ltrim(): It is used to remove whitespace from the left side of a string.
    • rtrim(): It is used to remove whitespace from the right side of a string.
    • sprint(): Return a formatted string.
    • strcasecmp(): It is used to compare two strings.
    • strncmp(): It is used to compare of the first n characters.
    • str_repeat(): It is used to repeat a string a specified number of times.
    • str_replace(): It replaces all occurrences of the search string with the replacement string.
    • str_split(): It is used to split a string into an array.

admin
http://www.learnwithgeeks.com

Leave a Reply