Phalcon Interview Questions and Answers

Phalcon is a PHP web framework based on the model–view–controller (MVC) pattern. It was created by Andrés Gutiérrez, originally released in 2012, it is an open-source framework licensed under the terms of the BSD License.Unlike most PHP frameworks, Phalcon is implemented as a web server extension written in Zephir and C, aiming to boost execution speed, reduce resource usage, and handle more HTTP requests per second than comparable frameworks written primarily in PHP. One drawback of this approach is that root/administrative access is required on the server to install Phalcon by building a custom binary or using a precompiled one.

Phalcon’s initial release was made available on November 14, 2012. Phalcon 3.0.0 was released on 29 July 2016, this major release includes support for PHP 7 as well as being Phalcon’s first LTS (Long Term Support) release. Phalcon also adopted SemVer for their next releases versioning.

Phalcon is an open source, high-performance PHP framework. It written as a C-extension, optimized for high performance. It is based on Module View Controller (MVC) pattern. Phalcon also is loosely coupled, allowing you to use its objects as glue components based on the needs of your application.

Zephir stands for Ze(nd Engine) Ph(p) I(nt)r(mediate) . It is a high-level language. It is used for creation and maintainability of extensions for PHP. It exported to C code that can be compiled and optimized by major C compilers such as gcc/clang/vc++.

Phalcon offers the object-oriented classes, necessary to implement the Model, View, Controller architecture in application. This design pattern is widely used by other web frameworks and desktop applications.

Models: A model represents the information (data) of the application and the rules to manipulate that data. Models are primarily used for managing the rules of interaction with a corresponding database table

Views: It represent the user interface of your application. Views are often HTML files with embedded PHP code that perform tasks related solely to the presentation of the data.

Controllers: It provide the “flow” between models and views. It is responsible for processing the incoming requests from the web browser, interrogating the models for data, and passing that data on to the views for presentation.

MVC benefits include:

Isolation of business logic from the user interface and the database layer

Making it clear where different types of code belong for easier maintenance

i18n = Internationalization: i, then 18 letters, then n. Internationalization is the process (or the concept of the process) to make an application “international”; that is, make it able to support virtually any language or local setting on Earth.

The component Phalcon\Translate aids in creating multilingual applications. Applications using this component, display content in different languages, based on the user’s chosen language supported by the application.

Volt is a Template engine of Phalcon.Volt is an ultra-fast and designer friendly templating language written in Zephir/C for PHP. It provides you a set of helpers to write views in an easy way. Volt is highly integrated with other components of Phalcon, just as you can use it as a stand-alone component in your applications.

In Phalcon, PHQL stands for Phalcon Query Language. It is a high-level SQL that standardize SQL queries for the database system. . PHQL is implemented as a parser (written in C) that translates syntax in that of the target RDBMS. To achieve the highest performance possible, Phalcon provides a parser that uses the same technology as SQLite. This technology provides a small in-memory parser with a very low memory footprint that is also thread-safe.

In Phalcon, when a process performs multiple database operations, it might be important that each step is completed successfully so that data integrity can be maintained. Transactions offer the ability to ensure that all database operations have been executed successfully before the data is committed to the database.

Backend is provided by logging services for application. We can login to different backend using different adapters. It offers transaction logging, configuration options, different formats and filters.

Cookie is a small text file stored by browser on user system. Cookies were designed to be a reliable mechanism for websites to remember stateful information or to record the user’s browsing activity.

Phalcon\Http\Response\Cookies is the directory where cookies are stored. Cookie management helps in storing cookies under the above directory during the request execution and is sent automatically at the end of the request.

Loader is a class found under Phalcon\Loader directory. This class consists of some pre-defined rules according to rules it loads class automatically. It also handles error such as if a class does not exist but it is called in any part of program then special handler is called for handling. In Loader if a class is added according to its need in program, performance is increased as only specific file is included. This technique is known as lazy initialization.

Registering Namespaces:If You’re organizing your code using namespaces, or using external libraries which do, the registerNamespaces() method provides the autoloading mechanism. It takes an associative array; the keys are namespace prefixes and their values are directories where the classes are located in. The namespace separator will be replaced by the directory separator when the loader tries to find the classes. Always remember to add a trailing slash at the end of the paths.

Registering Directories: The third option is to register directories, in which classes could be found. This option is not recommended in terms of performance, since Phalcon will need to perform a significant number of file stats on each folder, looking for the file with the same name as the class. It’s important to register the directories in relevance order. Remember always add a trailing slash at the end of the paths.

Registering Classes: The last option is to register the class name and its path. This autoloader can be very useful when the folder convention of the project does not allow for easy retrieval of the file using the path and the class name. This is the fastest method of autoloading. However, the more your application grows, the more classes/files need to be added to this autoloader, which will effectively make maintenance of the class list very cumbersome and it is not recommended.

Additional file extensions: Some autoloading strategies such as “prefixes”, “namespaces” or “directories” automatically append the “php” extension at the end of the checked file. If you are using additional extensions you could set it with the method “setExtensions”.

Password Hashing: This technique where password is stored in the encrypted form in the database. If the password is stored in the plain text format then any intruder that has the access to the database can easily view the passwords.

CSRF: Cross-Site Request Forgery protection (CSRF) protection is against the form elements such as in user registration or adding comments are vulnerable to this attack. CSRF is created to prevent the form values from being sent outside our application. To fix this, we generate a random nonce (token) in each form.