Download the PHP package ahmedzidan/php-core without Composer

On this page you can find all versions of the php package ahmedzidan/php-core. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-core

Latest Stable Version License Travis CI build status AppVeyor CI build status

Coveralls branch Scrutinizer Code Climate: GPA Total Downloads

Core

The core library provides the most basic functionality that is missing in PHP core (and most probably will never make it into it): helpers (in form of traits) to disable default PHP object behavior.

Installation

Open a terminal, enter your project directory and execute the following command to add this package to your dependencies:

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Usage

Disenchant

The Disenchant trait can be used to disable support for the magic __get, __isset, __set, and __unset methods. Every object in PHP by default supports these methods for dynamic property management. However, these are features that are actually undesired in almost all situations. While support for them does not lead to serious bugs, it can result in in weird behavior. Especially in the case of value objects when equality is determined with PHP’s equality operator (==).

Suppose we have a simple value object:

Using the equality operator to determine if two instances are equal or not is straight forward, the same is true for comparisons:

If we now add a property to $v0 the result will be different:

Of course, these operators should not be used and instead specialized functionality like Equalable and Comparable should be used, but this trait adds another layer of safety to the whole program at almost no cost.

Other situations in which this trait is very handy is if your objects rely on the properties they have. For instance if get_object_vars is used somewhere. However, note that not all possibly weird behavior is fixed through the inclusion of this trait. It is, for instance, still possible to dynamically add properties via specially crafted unserialize strings. This is because PHP does not call any of these magic methods in that case but directly adds the properties to the object, validate your objects in your __wakeup or unserialize methods instead.

Uncloneable

The Uncloneable trait can be used to disable support for the clone keyword in client code. This is a good idea for objects that cannot be cloned for technical reasons, e.g. anything that encloses a resource of some kind like a database connection, or should not be cloned because it makes no sense, e.g. any kind of immutable implementation like value objects.

The magic __clone method is defined as final and protected in this trait, this ensures that subclasses of the class that uses the trait are not able to alter that contract. At the same time it allows the using class to use the clone functionality internally to provide copy-on-write support without breaking changes; as illustrated in the following example:

Another interesting use-case are friend classes paired with the builder pattern to provide immutable entities.

Unconstructable

The Unconstructable trait can be used to disable support for the new keyword in client code. This is almost always a good idea to disable multiple constructor calls and enforce invariance for actual constructor method arguments. Of course, the class requires named constructors, otherwise construction would be impossible.

Another use-case are final abstract classes, which are not available in PHP.

Immutable

The Immutable is a combination of all other traits, and is provided for convenience only. It is best used for any kind of immutable class, as the name already suggests.

Testing

Open a terminal, enter the project directory and execute the following commands to run the PHPUnit tests with your locally installed PHP executable.

You can also execute the following two commands, in case make is not available on our system:


All versions of php-core with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ahmedzidan/php-core contains the following files

Loading the files please wait ....