Download the PHP package ocramius/lazy-property without Composer

On this page you can find all versions of the php package ocramius/lazy-property. 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 lazy-property

Lazy Property

This small library aims at providing a very simple and efficient loading of lazy properties

Latest Stable Version Latest Unstable Version

Abandoned

Starting with PHP 8.3, dynamic properties are no longer allowed "out of the box". While it is still possible to have dynamic properties via explicit declaration (the #[\AllowDynamicProperties] attribute), the approach of this package is no longer to be considered safe nor efficient long-term.

Based on that, this package is deprecated and abandoned: please use traditional PHP arrays instead.

Installation

The suggested installation method is via composer:

Use case

In many cases where lazy-initialization of private/protected properties is necessary, many people write classes that look like following:

This is problematic because implementors and people subclassing SomeService will eventually write:

This can work only if SomeService#getDependency() was called at least once upfront (which may well be under certain circumstances), and therefore is a cause of bugs/headaches/suicides/etc.

In order to avoid this problem, the implementor of SomeService that is also exposing its protected $dependency property may just use LazyProperty\LazyPropertiesTrait to fix the problem:

With this, any access to SomeService#$dependency will cause a call to SomeService#getDependency() if the property was not already initialized.

Please note that a getter is required in order for the property to be lazy.

Performance notes

Using LazyProperty\LazyPropertiesTrait allows to speed up applications where a massive amount of getter calls is going on in private/protected scope. There is some minor overhead in calling SomeService#initLazyProperties(), as well as in the first property access, but it should be negligible.


All versions of lazy-property with dependencies

PHP Build Version
Package Version
Requires php Version ~8.1.0 || ~8.2.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 ocramius/lazy-property contains the following files

Loading the files please wait ....