PHP Questions

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

How does PHP session work

A PHP session cookie is set in the clients browser, on every request the client sends that cookie to the server. PHP then uses that cookie to select the corresponding session information. By default PHP session_start() will store session data in files, you can also store sessions in a database.

What is a class

A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describes the details of an object.

Write basic concepts of OOP

Abstraction. Encapsulation. Inheritance. Polymorphism.

What is an abstract class

An abstract class is a class that contains at least one abstract method, which is a method without any actual code in it, just the name and the parameters, and that has been marked as "abstract". The purpose of this is to provide a kind of template to inherit from and to force the inheriting class to implement the abstract methods. An abstract class thus is something between a regular class and a pure interface. Also interfaces are a special case of abstract classes where ALL methods are abstract.

What is an object

An object for constructor as an instance of a class, and it has its own state, behavior, and identity

Singleton

An object is a singleton if the application can include one and only one of that object at a time

Public Property

Any class may instantiate the class and call the method or property.

What is static and dynamic binding

Binding is nothing but the association of a name with the class. Static binding is a binding in which name can be associated with the class during compilation time, and it is also called as early Binding. Dynamic binding is a binding in which name can be associated with the class during execution time, and it is also called as Late Binding.

What is Inheritance

Inheritance is a concept where one class shares the structure and behavior defined in another class. If inheritance applied on one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.

Polymorphism

It's simply the idea that one object can take on many forms. So in PHP OOP one class "cars" may have two classes that extend it, for example a "Honda" class and a "BMW" class.

Interface

Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled. All methods declared in an interface must be public; this is the nature of an interface.

Private Property

Only the class itself may call a method or property.

Protected Property

Only the class itself or inherited (children) classes may call a method or property

What is SQL Injection and how do you deal with that

SQL injection is a technique utilized by hackers to get access into your database by using malicious SQL statements. Using this, anyone can gain complete access to your database without any authorization or permission. To start with one need to use mysql_real_escape_string() to filter the user input data, before passing onto the sql statement.

How to destroy a session variable

Session_unregister() Unregister a global variable from the current session

Factory Pattern

The factory pattern is a class that has some methods that create objects for you. Instead of using new directly, you use the factory class to create objects. That way, if you want to change the types of objects created, you can change just the factory. All the code that uses the factory changes automatically.

Observer Pattern

This pattern is simple: One object makes itself observable by adding a method that allows another object, the observer, to register itself. When the observable object changes, it sends a message to the registered observers. What those observers do with that information isn't relevant or important to the observable object.

Traits

Traits is a mechanism for code reuse in single inheritance languages such as PHP. A Trait is intended to reduce some limitations of single inheritance by enabling a developer to reuse sets of methods freely in several independent classes living in different class hierarchies.

Please explain what is wrong with this query "Select * from table_name

You should never select all columns of a table unless needed and specify the columns only required in the query. The reason is that it will use a lot of memory to fetch the data, if the records are huge, when you are going to use only 2 or 3 fields from the table.

Encapsulation

exposes only necessary information to the calling functions Encapsulation is an attribute of an object, and it contains all data which is hidden. That hidden data can be restricted to the members of that class. Levels are Public, Protected, Private, Internal and Protected Internal.

In a PHP class what are the three visibility keywords of a property or method?

public, private and protected. The default is public.


संबंधित स्टडी सेट्स

Java - Arrays, ArrayLists, Generics

View Set

State Missed Questions FINAL STUDY SET

View Set

BI 218: Cell & Molecular Biology Exam 1 Chapters 1 & 3

View Set

Unit 2 Exam Review (Proctored Exam)

View Set

Intro chemistry Chpt 5 Chemical Accounting

View Set

earth's systems, solar radiation, El Niño and La Niña

View Set