Download the PHP package bapcat/propifier without Composer
On this page you can find all versions of the php package bapcat/propifier. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bapcat/propifier
More information about bapcat/propifier
Files in bapcat/propifier
Package propifier
Short Description A trait that improves PHP's properties
License GPL-3.0-or-later
Homepage https://github.com/BapCat/Propifier
Informations about the package propifier
Propifier
A trait that adds real object-oriented property support to PHP.
Installation
Composer
Composer is the recommended method of installation for all BapCat packages.
GitHub
BapCat packages may be downloaded from GitHub.
The Problem With PHP "Properties"
Anyone coming from another language like .NET will probably be accustomed to defining properties (accessors and mutators) to control access to private variables of a class. Unfortunately, PHP lacks support for this useful feature. There are several workarounds...
Public Properties
Using public properties is the easiest, but completely lacks encapsulation. You have no control over who can change the internal state of your object.
__get
and __set
Using PHP's late binding support gives you control over what can be read from and written to your object, but sacrifices readability, efficiency, and type hinting. It's also not possible to control read/write access to arrays this way without using other workarounds.
Getters and Setters
Using Java-style getters and setters is one of the best ways to implement properties in PHP, but still has flaws. It is very verbose:
You must also forgo using array access syntax to access array properties:
The Propifier Way
Propifier solves every one of these problems.
Efficiency
Propifier will make you more efficient at writing code that matters, and unlike similar solutions, Propifier is designed from the ground up to be fast. It figures everything out at the start, and maintains a static mapping of all of your objects' properties so using them is always fast.