why should one prefer call_user_func_array over regular calling of function? SO call_user_func_array is mostly used in dynamic contexts, when you don't know which function you will call and what arguments you are going to pass beforehand. In which scenario regular calling method will fail but call_user_func_array will not ? If you don't know beforehand how… Continue reading PHP imp
Tag: PHP
PHP 7 New Features
Link, Lynda.com VideoLynda.com Video Major Feature Scalar type hints Type hints have been available in PHP for while now. Unfortunately they were restricted to classes, arrays and callables. As of PHP 7, the scalar types (integers, floating point numbers, booleans and strings) can also be used as type hints. By default “coercive mode” is enabled. This restricts PHP from throwing a type… Continue reading PHP 7 New Features
ArrayAccess & Countable Interface
Like all of the predefined interfaces and SPL functionality the real power of these SPL comes from the ability to effectively override and re-implement core PHP functionality with your own logic. Link. ArrayAccess allows you to treat an object that implements it as if it is an array for the purposes of setting, unsetting and retrieving data from… Continue reading ArrayAccess & Countable Interface
PHP Garbage Collection
PHP performs garbage collection at three primary junctures: When you tell it to When you leave a function When the script ends PHP garbage collection works on reference count. unset your global variables as soon as you don't need them. PHP keeps a reference count for all variables and destroys them (in most conditions) as soon… Continue reading PHP Garbage Collection
Laravel: Lazy Load and Lazy Eager Loading
Laravel Lazy Load If you do not need to add additional constraints to an Eloquent relationship query, you may simply access the relationship as if it were a property. For example, continuing to use our User and Postexample models, we may access all of a user's posts like so: $user = App\User::find(1); foreach ($user->posts as $post) { //… Continue reading Laravel: Lazy Load and Lazy Eager Loading
Monitoring Processes with Supervisord
Supervisord is a simple and popular choice for process monitoring. Supervisor is a client/server system that allows its users to control a number of processes on UNIX-like operating systems. Supervisord is a script monitoring tool. Below is the conf file which. [program:nodehook] command=/usr/bin/node /srv/http.js directory=/srv autostart=true autorestart=true startretries=3 stderr_logfile=/var/log/webhook/nodehook.err.log stdout_logfile=/var/log/webhook/nodehook.out.log user=www-data environment=SECRET_PASSPHRASE='this is secret',SECRET_TWO='another secret'… Continue reading Monitoring Processes with Supervisord
Speed Up PHP
APC-Cache Zend engine needs 4 steps to run a PHP script 1. Read PHP code from file into memory 2. Lexing : convert to lexicons that can form syntax 3. Parsing and compiling : parsing lexicons into opcodes and validate language syntax 4. Executing: execute opcodes APC mainly hijacks step 3. Instead of having Zend… Continue reading Speed Up PHP
Session and Cookies
These link basically sum up session very well. It's a very trivial topic to cover but nonetheless very fundamental. Sometimes interviewers dig into these topics (mostly for freshers or less experienced applicants). The explanation is very simple and the best part is the debug part which has been copied below. https://www.quora.com/How-Session-and-Cookies-related or http://machinesaredigging.com/2013/10/29/how-does-a-web-session-work/ Why would a… Continue reading Session and Cookies
PHP
PHP is compiled down to an intermediate bytecode that is then interpreted by the runtime engine. The PHP compiler's job is to parse your PHP code and convert it into a form suitable for the runtime engine. Among its tasks: Ignore comments Resolve variables, function names, and so forth and create the symbol table Construct… Continue reading PHP
Reflection Class
Usage - Dynamic typing is probably impossible without reflection. Aspect Oriented Programming listens from method calls and places code around methods, all accomplished with reflection. PHPUnit relies heavily on reflection, as do other mocking frameworks. Really good article to read - ** https://code.tutsplus.com/tutorials/reflection-in-php--net-31408 *http://culttt.com/2014/07/02/reflection-php/
You must be logged in to post a comment.