Download the PHP package marein/php-friend-visibility without Composer

On this page you can find all versions of the php package marein/php-friend-visibility. 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-friend-visibility

php-friend-visibility

Table of contents

Foreword / Why this package?

I love php. But sometimes I miss some features I know from other languages like CSharp, Java or C++. These features are, for example, friend classes, package visibility and so on. Here is a rfc for friend classes. I would love to see this or some package visibility in php. Hopefully someday.

Be aware of, that friend classes breaks encapsulation. If you change the class which has friends, you must check your friends if something has changed they use. If you rely on reflection to access private properties, this becomes a nightmare, because the code is accessed from everywhere. Friends on the other side, are well documented in code. Another good example for explicit code vs. reflection is the visitor pattern. You can implement a visitor-pattern–like implementation with reflection but this is not expressive. If you add another subclass to your tree, you have to know which classes you have to change. With the real visitor pattern, you implement an interface which gets extended if you throw a new subclass into the match. Now, you can clearly see which visitor you have to change and implement the new method for the new subclass.

So, hopefully someday we get friend classes.

Please reconsider your design before you use this package. It's easy to break encapsulation, but it's hard to do object oriented programming properly. Even if you can easily add this package to your toolkit, everyone in your team should agree. It's not a language feature, and someone may don't know what friend classes are or what your design intention is. As with everything: Think before you use it!

Last but not least: The idea how this is implemented is not mine. It's a copy from Patrick van Bergen (big thanks). I used to use a trait instead of a base class for the friendship behaviour. The whole article is worth reading. The implementation is similar to mine.

I've created this repository because I want an easy installation.

Installation

Usage

Take a look at the example. It's an implementation of the state pattern.

Performance

To access private and protected members is of course slower than direct calls, because of the black magic. This package use [debug_backtrace, __get, __set, __call, __callStatic]. You may should do a performance test for your project. However, you can enable the production mode with

The code should run much faster now. This is because all checks are disabled. Everything is now public in the classes which use the trait. Because of that, this should not be enabled in development.

Test case Time in milliseconds
Access one public method 0,003 ms
Access one private method 0,006 ms
Access one private method in production 0,004 ms

All versions of php-friend-visibility with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
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 marein/php-friend-visibility contains the following files

Loading the files please wait ....