jbboehr / php-psr Goto Github PK
View Code? Open in Web Editor NEWPHP extension providing the accepted PSR interfaces
License: Other
PHP extension providing the accepted PSR interfaces
License: Other
Originally issue came from the Magento 2: magento/magento2#30575
We faced an issue with auto-generated proxy code based on the \Psr\Log\LoggerInterface.
Investigation shown that actually issue was caused by psr
php extension - seems like default value isn't specified, while on original LoggerInterface we do have optional context
argument wit default value - empty array.
Tested on php 7.3 and php 7.4, both versions having the same issue.
I was able to reproduce this issue even on a simple file (checked on emergency method, but issue the same for others):
<?php
include "./vendor/autoload.php";
$reflectionMethod = new \ReflectionMethod(\Psr\Log\LoggerInterface::class, "emergency");
$reflectionParameter = $reflectionMethod->getParameters()[1];
var_dump($reflectionParameter->isOptional());
var_dump($reflectionParameter->isDefaultValueAvailable());
var_dump($reflectionParameter->getDefaultValue());
and psr/log
installed through composer.
✔ Result without psr
extension
app@3bedbfa9e5db:~/html/pub$ php index.php
bool(true)
bool(true)
array(0) {
}
❌ Result with psr
extension
app@3bedbfa9e5db:~/html/pub$ php index.php
bool(true)
bool(false)
Fatal error: Uncaught ReflectionException: Cannot determine default value for internal functions in /var/www/html/pub/index.php:8
Stack trace:
#0 /var/www/html/pub/index.php(8): ReflectionParameter->getDefaultValue()
#1 {main}
thrown in /var/www/html/pub/index.php on line 8
See php-fig/log#57
IIUC, this is not part of the PSR-3, but provided by the psr/log pure-PHP library
This extension currently breaks libraries that provide an implementation of psr/container
1.1, like Pimple 3.4 or Symfony DI 5.3.
composer.json
{
"require": {
"psr/container": "^1.1"
}
}
MyContainer.php
<?php
use Psr\Container\ContainerInterface;
require __DIR__.'/vendor/autoload.php';
class MyContainer implements ContainerInterface
{
public function has(string $id)
{
return false;
}
public function get(string $id)
{
throw new class extends \Exception implements NotFoundExceptionInterface {};
}
}
Output
Fatal error: Declaration of MyContainer::get(string $id) must be compatible with Psr\Container\ContainerInterface::get($id) in /path/to/MyContainer.php on line 14
The script is executed correctly if I disable the psr
extension.
May I propose bumping the next version (or making a release without changes) to 1.0.0?
I'm asking this mainly due to SemVer's and Composers well-defined differences between pre-1.0 and all other version strings for comparison purposes (as ^0.7.0
means >= 0.7.0 <0.8.0
), so it's likely to make life a bit easier long-term for the interoperability of components that want to rely on the extension.
I think we're way overdue for a release of 0.3.0. I think it should be safe to include #31 with my PHP5 compatibility changes.
@sergeyklay Is there anything you want in before release?
Hello, I am using the extension to use the PSR interfaces in a separate Zephir extension.
My method receives as a parameter a ServerRequestInterface and when invoking the method getUri() reports: Class 'Psr\Http\Message\ServerRequestInterface' does not implement method: 'getUri'
Example:
public function handle(<ServerRequestInterface> request) -> <ResponseInterface> {
// error:
var_dump(request->getUri()->getPath());
// ok:
var requestBase;
let requestBase = new RequestInterface();
let requestBase = request;
var_dump(requestBase->getUri()->getPath());
}
To solve this I must create a new variable of type RequestInterface to "convert" the type of object.
Do you know what may be happening?
Thank you
Hi there,
I have trying to install PSR (from source) on PHP 7.4 (from Ondrej repo), but got this error
$ php7.4 --ri psr
PHP Warning: PHP Startup: psr: Unable to initialize module
Module compiled with module API=20180731
PHP compiled with module API=20190902
These options need to match
in Unknown on line 0
PHP Warning: Cannot load module 'phalcon' because required module 'psr' is not loaded in Unknown on line 0
Extension 'psr' not present.
My system
$ uname -a
Linux dev.eslabs.id 4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
$ /usr/bin/phpize7.4 --version
Configuring for:
PHP Api Version: 20190902
Zend Module Api No: 20190902
Zend Extension Api No: 320190902
$ /usr/bin/php-config7.4 --version
7.4.1
any solutions?
thanks
Hi @jbboehr and others,
PHP 8.0.0 is getting really close and it looks like this extension supports it already.
All that's missing is a Git tag, and a release to PECL :)
Would be super if that could be done anytime soon so that e.g. PaaSes have a stable release version to provide to customers.
Thanks!
Installing the PSR extension for PHP 7.2 can sometimes be challenging, especially if you encounter errors during the build or installation process. Here is my experience: I followed the steps you provided to install the PSR extension for PHP 7.2, but encountered an error during the build process:
# /usr/local/php72/bin/phpize
# ./configure --with-php-config=/usr/local/php72/bin/php-config
...
# make
/bin/sh /usr/local/src/php-psr/libtool --mode=compile cc -I. -I/usr/local/src/php-psr -DPHP_ATOM_INC -I/usr/local/src/php-psr/include -I/usr/local/src/php-psr/main -I/usr/local/src/php-psr -I/usr/local/php72/include/php -I/usr/local/php72/include/php/main -I/usr/local/php72/include/php/TSRM -I/usr/local/php72/include/php/Zend -I/usr/local/php72/include/php/ext -I/usr/local/php72/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/php-psr/psr_cache.c -o psr_cache.lo
cc -I. -I/usr/local/src/php-psr -DPHP_ATOM_INC -I/usr/local/src/php-psr/include -I/usr/local/src/php-psr/main -I/usr/local/src/php-psr -I/usr/local/php72/include/php -I/usr/local/php72/include/php/main -I/usr/local/php72/include/php/TSRM -I/usr/local/php72/include/php/Zend -I/usr/local/php72/include/php/ext -I/usr/local/php72/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/php-psr/psr_cache.c -fPIC -DPIC -o .libs/psr_cache.o
In file included from /usr/local/src/php-psr/psr_cache.c:15:
/usr/local/src/php-psr/psr_private.h: In function ‘php_psr_register_interface’:
/usr/local/src/php-psr/psr_private.h:17: error: too many arguments to function ‘zend_register_class_alias_ex’
In file included from /usr/local/src/php-psr/psr_cache.c:15:
/usr/local/src/php-psr/psr_private.h: In function ‘php_psr_register_class’:
/usr/local/src/php-psr/psr_private.h:53: error: too many arguments to function ‘zend_register_class_alias_ex’
make: *** [psr_cache.lo] Error 1
Build OK.
TEST 8/43 [tests/PsrHttpClientClientExceptionInterface.phpt]
========DIFF========
001+ Warning: class_implements(): Class Psr\Http\Client\ClientExceptionInterface does not exist in /builddir/build/BUILD/php56-php-pecl-psr-0.6.0/NTS/tests/PsrHttpClientClientExceptionInterface.php on line 3
002+ bool(false)
003+
004+ Fatal error: Interface 'Psr\Http\Client\ClientExceptionInterface' not found in /builddir/build/BUILD/php56-php-pecl-psr-0.6.0/NTS/tests/PsrHttpClientClientExceptionInterface.php on line 4
001- array(1) {
002- ["Throwable"]=>
003- string(9) "Throwable"
004- }
005- bool(true)
006- bool(true)
007- bool(true)
008- string(4) "test"
========DONE========
FAIL Psr\Http\Client\ClientExceptionInterface [tests/PsrHttpClientClientExceptionInterface.phpt]
TEST 9/43 [tests/PsrHttpClientClientInterface.phpt]
========DIFF========
001+ Parse error: syntax error, unexpected ':', expecting ';' or '{' in /builddir/build/BUILD/php56-php-pecl-psr-0.6.0/NTS/tests/SampleClient.inc on line 9
001- bool(true)
002- array(1) {
003- ["Psr\Http\Client\ClientInterface"]=>
004- string(31) "Psr\Http\Client\ClientInterface"
005- }
006- string(25) "SampleClient::sendRequest"
007- object(SampleRequest)#%d (0) {
008- }
009- bool(true)
========DONE========
FAIL Psr\Http\Client\ClientInterface [tests/PsrHttpClientClientInterface.phpt]
TEST 10/43 [tests/PsrHttpClientNetworkExceptionInterface.phpt]
========DIFF========
001+ Parse error: syntax error, unexpected ':', expecting ';' or '{' in /builddir/build/BUILD/php56-php-pecl-psr-0.6.0/NTS/tests/PsrHttpClientNetworkExceptionInterface.php on line 8
001- array(2) {
002- ["Psr\Http\Client\ClientExceptionInterface"]=>
003- string(40) "Psr\Http\Client\ClientExceptionInterface"
004- ["Throwable"]=>
005- string(9) "Throwable"
006- }
007- bool(true)
008- bool(true)
009- bool(true)
010- bool(true)
011- string(4) "test"
012- string(23) "MyException::getRequest"
013- object(SampleRequest)#%d (0) {
014- }
========DONE========
FAIL Psr\Http\Client\NetworkExceptionInterface [tests/PsrHttpClientNetworkExceptionInterface.phpt]
TEST 11/43 [tests/PsrHttpClientRequestExceptionInterface.phpt]
========DIFF========
001+ Parse error: syntax error, unexpected ':', expecting ';' or '{' in /builddir/build/BUILD/php56-php-pecl-psr-0.6.0/NTS/tests/PsrHttpClientRequestExceptionInterface.php on line 8
001- array(2) {
002- ["Psr\Http\Client\ClientExceptionInterface"]=>
003- string(40) "Psr\Http\Client\ClientExceptionInterface"
004- ["Throwable"]=>
005- string(9) "Throwable"
006- }
007- bool(true)
008- bool(true)
009- bool(true)
010- bool(true)
011- string(4) "test"
012- string(23) "MyException::getRequest"
013- object(SampleRequest)#%d (0) {
014- }
========DONE========
FAIL Psr\Http\Client\RequestExceptionInterface [tests/PsrHttpClientRequestExceptionInterface.phpt]
e.g.
zend_class_entry ce;
INIT_NS_CLASS_ENTRY(ce, GUZZLE_NS, "Client", guzzle_client_method);
guzzle_client_ce = zend_register_internal_class(&ce);
zend_do_implement_trait(guzzle_client_ce, PsrLogLoggerTrait_ce_ptr);
zend_do_bind_traits(guzzle_client_ce); // zend_add_trait_method --> zend_arena_alloc error
Omitting the second argument to the functions in AbstractLogger appear to not forward the argument on as an array.
Hey,
I'm from PHP-FIG group.
I'm working on phalcon project with @sergeyklay.
I'm integrating PSR-11 ContainerInterface .. I created this bash script to install psr.so
..
My question is .. I don't like how path to conf.d
is hard coded .. do you have a good way to auto-detect this ?
#!/usr/bin/env bash
set -ex
apt-get update -y
apt-get install -y nano tree git gnupg gcc make re2c autoconf automake
mkdir -p /tmp/psr-ext-setup
cd /tmp/psr-ext-setup
rm -rf /tmp/psr-ext-setup/php-psr
git clone https://github.com/jbboehr/php-psr.git
cd php-psr
phpize
./configure
make
make test
make install
rm -rf /var/lib/apt/lists/*
echo extension=psr.so | tee -a /etc/php/7.1/cli/conf.d/psr.ini
php -m | grep psr
$ pecl download psr-0.6.1
Failed to download pecl/psr, version "0.6.1", latest release is version 0.6.0, stability "stable",
use "channel://pecl.php.net/psr-0.6.0" to install
download failed
I propose move all build related stuff to the common place, e.g. build
, ci
or something like that.
Hello @jbboehr,
It's not a real issue. I just wanted to say you thanks and show you a page which says that we are dependent on php-psr extension: https://docs.phalconphp.com/4.0/en/installation
I think Phalcon is the first so large and public project requiring php-psr extension.
Thank you helping us make Phalcon better.
P.S. Feel free to close this issue after reading
After compiling master or v7.0 (from Github) I get the following errror:
php -v
php: symbol lookup error: /usr/local/lib64/extensions/no-debug-non-zts-20180731/psr.so: undefined symbol: zm_startup_psr_event_dispatcher
PHP gets unusable.
Btw: version 0.6.1 works fine!
I have a question, and I apologise in advance if GitHub issues is not the right channel for asking this.
What exactly is the purpose of this extension? The project read me says
You can use interfaces provided by this extension in another extension easily
Does that mean that the extension is only for use with other extensions that depend on this? Is there any advantage in standalone use of this extension instead of the standard composer package offered by PHP-FIG?
Since PHP8.1 it is more stricter.
Line 145 in 920e4dd
Change from:
PHP_PSR_BEGIN_ARG_INFO(HttpMessage, StreamInterface, __toString, 0)
To:
#if PHP_VERSION_ID >= 80000
PHP_PSR_BEGIN_ARG_WITH_RETURN_TYPE_INFO(HttpMessage, StreamInterface, __toString, 0, IS_STRING, 0)
#else
PHP_PSR_BEGIN_ARG_INFO(HttpMessage, StreamInterface, __toString, 0)
#endif
Also this one:
PHP Fatal error: Declaration of Psr\Http\Message\UriInterface::__toString() must be compatible with Stringable::__toString(): string
Found in https://github.com/zephir-lang/zephir/runs/4132222740?check_suite_focus=true#step:11:12
Currently there is a 2.0 out of psr/container
and psr/link
which require PHP 8.0 and are not compatible with the libraries we test against. We should review other PSR repos for newer versions develop an upgrade plan.
See #84
I am pleased to announce that this extension is now compiled for Windows by the PHP Extension Repository site.
You can download the DLLs on the extension page: https://phpext.phptools.online/extension/php/psr-252
If you have any questions, I am available to discuss them.
I do appreciate all OS contributions and I really don't want to discourage others work. But I need to inform you that there is a huge problem when people are using this extension.
Since the code is loaded with PHP, it will avoid all composer version negotiation. Which means a user will always have psr/container:X and when they download a package that only supports psr/container:Y composer will not complain but the user will get an error at runtime.
I see that you have a section in the readme to inform users about this problem but it has two problems:
I see a lot of confused users reporting issues they get after installing libraries that I maintain.
Example:
Fatal error: Declaration of Symfony\Component\DependencyInjection\ServiceLocator::has(string $id) must be compatible with Psr\Container\ContainerInterface::has($id) in vendor/symfony/dependency-injection/ServiceLocator.php on line 46
I strongly suggest this should be the top priority to fix. Especially since the problem will get way worse with #87.
I'm compiling php-psr on a fresh CentOS 8 installation, which at the time of writing comes with PHP 7.2.24, and it won't compile with that version due to an incompatibility with the zend API header:
In file included from /home/gerben/php-psr/psr_cache.c:15:
/home/gerben/php-psr/psr_private.h: In function ‘php_psr_register_interface’:
/home/gerben/php-psr/psr_private.h:17:5: error: too many arguments to function ‘zend_register_class_alias_ex’
zend_register_class_alias_ex(class_alias, class_alias_len, class_entry, 1);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/php/main/php.h:39,
from /home/gerben/php-psr/psr_cache.c:6:
/usr/include/php/Zend/zend_API.h:307:14: note: declared here
ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
So psr_private.h calls zend_register_class_alias_ex
with 4 arguments:
zend_register_class_alias_ex(class_alias, class_alias_len, class_entry, 1);
But zend_API.h
expects only 3 arguments:
ZEND_API int zend_register_class_alias_ex(const char *name, size_t name_len, zend_class_entry *ce);
The last version where 3 arguments where still expected was 7.2.24:
https://github.com/php/php-src/blob/PHP-7.2.24/Zend/zend_API.h#L307
It expects 4 arguments since PHP version 7.3:
https://github.com/php/php-src/blob/PHP-7.3/Zend/zend_API.h#L289
Can you please update the php-psr README.md requirements to something along the lines of "PHP >= 7.3 development headers and tools"?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.