Professional Documents
Culture Documents
General PHP
Traits are 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. The semantics of the combination of Traits and classes is
defined in a way which reduces complexity, and avoids the typical problems associated
with multiple inheritance and Mixins.
A Trait is similar to a class, but only intended to group functionality in a fine-grained and
consistent way. It is not possible to instantiate a Trait on its own. It is an addition to
traditional inheritance and enables horizontal composition of behavior; that is, the
application of class members without requiring inheritance.
interface abc
{
public function xyz($b);
}
Note: In abstract classes, this is not necessary that every method should be
abstract. But in interface every method is abstract.
6 - Difference between unset()/unlink()
7 - Final Class/Method and what error can it produce?
8 - What are PSRs?
PSRs are PHP Standards Recommendations that aim at standardising common
aspects of PHP Development.
9 - Have you followed any PSR for your projects if so can you
state some of the points.
Laravel
Base:
1- How long have you been using Laravel?
2- Why Laravel over other PHP frameworks?
3- What is your favorite feature of Laravel?
4- Have you used Lumen before?
Lumen is the micro-framework by Laravel that was made by
Taylor specifically for APIs and microservices. If they've decided to use
Lumen over Larvel for a microservice or API, it shows that they care
about performance.
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
//
});
Route::any('foo', function () {
//
});
If you open the config/app.php file included with Laravel, you will see
a providers array. These are all of the service provider classes that will be
loaded for your application. Of course, many of these are "deferred" providers,
meaning they will not be loaded on every request, but only when the services
they provide are actually needed.
b - service containers:
The Laravel service container is a powerful tool for managing class
dependencies and performing dependency injection. Dependency injection is
a fancy phrase that essentially means this: class dependencies are "injected"
into the class via the constructor or, in some cases, "setter" methods.
use Illuminate\Support\Facades\Cache;
Route::get('/cache', function () {
return Cache::get('key');
});
Unlike facades, which do not require you to require them in your class'
constructor, contracts allow you to define explicit dependencies for your
classes. Some developers prefer to explicitly define their dependencies in this
way and therefore prefer to use contracts, while other developers enjoy the
convenience of facades.
9. what is Method Spoofing?
HTML forms do not support PUT, PATCH or DELETE actions. So, when
defining PUT, PATCH or DELETE routes that are called from an HTML form, you will need to add a
hidden _method field to the form.
If they've never had to write any custom middleware then they most
likely have not written any complex applications, or were not the lead
engineer on a complex application project.
return strtoupper($name);
})
->reject(function ($name) {
return empty($name);
});
As you can see, the Collection class allows you to chain its methods to
perform fluent mapping and reducing of the underlying array. In general,
collections are immutable, meaning every Collectionmethod returns an entirely
new Collection instance.
Tap: Laravel 5.4.10 introduces a new tap method on collections which allow you to tap
into the collection at a specific point and do something with the results while not
affecting the main collection.
Pipe: Laravel also provides another similar method to tap named pipe and they are
similar in that they can be performed inside a collection pipeline. However, they have
two primary differences:
Tap allows you to do something with the data available but it does not modify the
original. Pipe modifies the results in the collection based on its return value.
The best way to explain this feature is with an example. In Laravel 5.2 you would
typically send an email like the following that is outlined in the documentation:
});
return [
];
18. How would you add a 3rd party package like Sentry?
OR
'desc')->skip(1)->take(1)->get();