Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Zend\Stdlib\ArrayObject::offsetExists() returning by reference #3714

Merged
merged 1 commit into from

7 participants

Andreas Hager Ivo van Beek Matthew Weier O'Phinney asmitamahamuni Mohammad ZeinEddin Thomas Misilo Evan Coury
Andreas Hager

Since the release of Zend Framework 2.1.1 I have got the following error message when developing:

Fatal error: Declaration of Zend\Stdlib\ArrayObject::offsetExists() must be compatible with that of ArrayAccess::offsetExists() .../vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php on line 25

The problem is, that the latest version of debian squeeze only provides php5 (5.3.3-7 source: http://packages.debian.org/squeeze/php5).
The returning by reference feature from the ArrayAccess::offsetGet() method is only implemented since version 5.3.4 (Starting with PHP 5.3.4, the prototype checks were relaxed and it's possible for implementations of this method to return by reference. source: http://www.php.net/manual/en/arrayaccess.offsetget.php).

There is no stable release from debian which provides a greater php version. So everyone which uses debian squeeze has to compile a newer php version by themself.

The current system requirements from Zend Framework 2 are 5.3.3 (source: https://github.com/zendframework/zf2). Did you bump up the requirements to php 5.3.4 for ZF 2.1.1 on purpose?

Ivo van Beek

The same goes for the error beneath...
Fatal error: Declaration of Zend\Stdlib\ArrayObject::offsetGet() must be compatible with that of ArrayAccess::offsetGet() in /var/www/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php on line 25.

Matthew Weier O'Phinney
Ivo van Beek

wierophinney, I'm quite new to ZF2... But I'm using composer and when I was installing ZF2 no error or notification showed...

I've already updated to php 5.4.
For people who want to do that aswell: http://www.dotdeb.org/2011/01/11/php-5-3-5-now-for-squeeze/.

Andreas Hager

Thanks for your reply.

Yes i use composer. I check now the php version (PHP_VERSION: 5.3.3-7+squeeze14) and from CLI (PHP 5.3.3-7+squeeze14 with Suhosin-Patch (cli) (built: Aug 6 2012 14:18:06)).
After that i tried to add your line to the init_autoloader.php, but the same error message. I put the loading also on the top of the file, but error message appears again. Then i realized that the autoloader generated by composer already has the line in the loader (Line 41+42).

public static function getLoader()
{
    ...
    require $vendorDir . '/zendframework/zendframework/library/Zend/Stdlib/compatibility/autoload.php';
    require $vendorDir . '/zendframework/zendframework/library/Zend/Session/compatibility/autoload.php'
    ...
}
Andreas Hager

I still get the same error message. I did now a rollback to ZF 2.1.0.
Any ideas? :)

asmitamahamuni

Hii,

I am also getting following error,

Fatal error: Declaration of Zend\Stdlib\ArrayObject::offsetGet() must be compatible with that of ArrayAccess::offsetGet() in /var/www/vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php on line 25.

Mohammad ZeinEddin

I am also having this problem... I just used composer to install zend framework 2.1.2 on Linux, PHP 5.3.3, and I get the following error:
PHP Fatal error: Declaration of Zend\Stdlib\ArrayObject::offsetGet() must be compatible with that of ArrayAccess::offsetGet() in vendor/zendframework/zendframework/library/Zend/Stdlib/ArrayObject.php on line 25
When I got back to 2.1.0 the error disappeared!

Matthew Weier O'Phinney
Mohammad ZeinEddin

I am using composer autoloader... I just install everything (ZF2 and doctrine ORM) using composer... and when run my application... and I got this error...
here is the output of php --version:
PHP 5.3.3 (cli) (built: Jul 3 2012 16:53:21)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Matthew Weier O'Phinney

@ZeinEddin I've confirmed.

What's happening is this:

  • Composer sets up both the PSR-0 and classmap autoloaders first, and then requires any files specified in the autoload.files array.
  • Interestingly, those autoload.files require statements are not made in the order they are presented in composer.json, but instead alphabetized.
  • As a result, the first file that is loaded under 5.3.3 is Zend\Session\Container, which depends on AbstractContainer... which extends Zend\Stdlib\ArrayObject.

The result is that because the PHP 5.3.3 compatibility file for Zend\Stdlib\ArrayObject has not yet been loaded, one of the other autoloaders kicks in, and the >=5.3.4 variant is used.

I'll try and get a fix for this today, and do a patch release for 2.1.2.

Mohammad ZeinEddin

If you can make this patch today, let us know... maybe I can test it... :)

Matthew Weier O'Phinney weierophinney [#3714] Fix issues with 5.3.3 polyfills
- When installing the entire framework, the `autoload.files` of
  `composer.json` are sorted alphabetically. This causes an issue, as
  the `Zend\Session` polyfill depends on the `Zend\Stdlib` polyfill.
- When installing the components separately, they are sorted based on
  dependencies, and thus the require statements happen in the correct
  order.
- The solution presented here is to test if (a) the polyfill class is
  already declared, and (b) if not, attempt to load the polyfill based
  on the known directory structure.
a9d343d
Andreas Hager

I did an update to zf 2.1.2 and the problem has gone.

Thomas Misilo

I get the error with Scientific Linux 6.3

PHP 5.3.3 (cli) (built: Jun 27 2012 14:13:03) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Xdebug v2.1.4, Copyright (c) 2002-2012, by Derick Rethans

And zf 2.1.2

*Edit actually mine is erroring on Declaration of Zend\Stdlib\ArrayObject::offsetGet() must be compatible with that of ArrayAccess::offsetGet()

Matthew Weier O'Phinney

@andreashager and @misilot Please apply the patch to your vendor/zendframework/zendframework/ directory and test. I've tested on a 5.3.3 host, and it appears to work, but I'd like independent verification.

Thomas Misilo

@weierophinney Still giving me the same error.

Matthew Weier O'Phinney

Here is my note on the commit:

  • When installing the entire framework, the autoload.files of composer.json are sorted alphabetically. This causes an issue, as the Zend\Session polyfill depends on the Zend\Stdlib polyfill.
  • When installing the components separately, they are sorted based on dependencies, and thus the require statements happen in the correct order.
  • The solution presented here is to test if (a) the polyfill class is already declared, and (b) if not, attempt to load the polyfill based on the known directory structure.
Matthew Weier O'Phinney

@misilot How did you patch? did you use the diff from commit a9d343d ?

Alternately, do the following in your composer.json:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "git://github.com/weierophinney/zf2.git"
        }
    ],
    "minimum-stability": "dev",
    "require": {
         "zendframework/zendframework": "dev-hotfix/3714"
    }
}

Then do a php composer.phar update.

I did this on a repo just now, and before the update, under PHP 5.3.3, I got the exception as reported; afterwards, it worked.

Thomas Misilo

@weierophinney i copied the text and put it into the two files in vendor/ZF2/library/Zend/Session/compatibility/autoload.php and vendor/ZF2/library/Zend/Stdlib/compatibility/autoload.php

I am not using compser.json, so I did not do that method.

patch -p1 < a9d343d.patch 
patching file library/Zend/Session/compatibility/autoload.php
patching file library/Zend/Stdlib/compatibility/autoload.php

Still same error:

PHP Fatal Error: Declaration of Zend\\Stdlib\\ArrayObject::offsetGet() must be compatible with that of ArrayAccess::offsetGet() in /site/vendor/ZF2/library/Zend/Stdlib/ArrayObject.php on line 25

Do I need to update anything in the SkeletonApplication or should I just be able to drop in zf2.1.2 into the vendor directory?

Matthew Weier O'Phinney

@misilot You're not using composer for autoloading? If that's the case, you have to do things differently.

Setup your main application autoloader, and then require the compat autoload files. In the skeleton application's init_autoloader.php file, after line 43, add the following:

require $zf2Path . '/Zend/Stdlib/compatibility/autoload.php';
require $zf2Path . '/Zend/Session/compatibility/autoload.php';

I'll make this change in the skeleton application today -- but that should correct things for you. Please report back and let me know.

Matthew Weier O'Phinney weierophinney referenced this pull request from a commit in weierophinney/ZendSkeletonApplication
Matthew Weier O'Phinney weierophinney Add polyfill support for non-composer autoloading
- Ensure that if composer is not used for autoloading, polyfills are still
  required. See zendframework/zf2#3714 for details
a52ef06
Matthew Weier O'Phinney weierophinney referenced this pull request in zendframework/ZendSkeletonApplication
Merged

Polyfill support for non-composer autoloading #165

Matthew Weier O'Phinney

@misilot See zendframework/ZendSkeletonApplication#165 for the related patch on that repository.

Thomas Misilo

@weierophinney thank you that worked.

Matthew Weier O'Phinney

@andreashager @pcwivo @ZeinEddin Can one of you test the patch, potentially
following the instructions in this comment:

I'd like to get independent verification that the changes work.

Matthew Weier O'Phinney

@weierophinney thank you that worked.

Awesome -- thanks for testing, @misilot !

Evan Coury EvanDotPro commented on the diff
library/Zend/Session/compatibility/autoload.php
@@ -1,5 +1,11 @@
<?php
if (version_compare(PHP_VERSION, '5.3.4', 'lt')) {
+ if (!class_exists('Zend\Stdlib\ArrayObject', false)
+ && file_exists(__DIR__ . '/../../Stdlib/compatibility/autoload.php')
Evan Coury Collaborator

Should this be is_readable()?

Matthew Weier O'Phinney Owner

Either one will work. Both do stat checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Evan Coury EvanDotPro merged commit a9d343d into from
Matthew Weier O'Phinney weierophinney deleted the branch
Andreas Hager

@weierophinney also works for me, awesome! :)

Mohammad ZeinEddin

I am sorry for late reply... but I just did a composer update and installed 2.1.3 and it didn't work... and so I fall back again to 2.1.0 and it worked fine on it! should I do anything other than composer update command?

here is the error with the error call stack in case it helps (the error exists on zf2 > 2.1.0):

( ! ) Fatal error: Declaration of Zend\Stdlib\ArrayObject::offsetGet() must be compatible with that of ArrayAccess::offsetGet() in ...\vendor\zendframework\zendframework\library\Zend\Stdlib\ArrayObject.php on line 25
Call Stack
Time Memory Function Location
1 0.0006 369048 {main}( ) ..\index.php:0
2 0.0109 573800 Zend\Mvc\Application::init( ) ..\index.php:17
3 0.1177 3374168 Zend\ServiceManager\ServiceManager->get( ) ..\Application.php:239
4 0.1178 3374592 Zend\ServiceManager\ServiceManager->create( ) ..\ServiceManager.php:441
5 0.1178 3374624 Zend\ServiceManager\ServiceManager->createFromFactory( ) ..\ServiceManager.php:494
6 0.1182 3379120 Zend\ServiceManager\ServiceManager->createServiceViaCallback( ) ..\ServiceManager.php:867
7 0.1183 3379360 call_user_func ( ) ..\ServiceManager.php:737
8 0.1183 3379384 Zend\Mvc\Service\ApplicationFactory->createService( ) ..\ServiceManager.php:0
9 0.1183 3379880 Zend\Mvc\Application->__construct( ) ..\ApplicationFactory.php:29
10 0.1185 3380552 Zend\ServiceManager\ServiceManager->get( ) ..\Application.php:100
11 0.1185 3380968 Zend\ServiceManager\ServiceManager->create( ) ..\ServiceManager.php:441
12 0.1185 3381000 Zend\ServiceManager\ServiceManager->createFromFactory( ) ..\ServiceManager.php:494
13 0.1189 3386136 Zend\ServiceManager\ServiceManager->createServiceViaCallback( ) ..\ServiceManager.php:867
14 0.1189 3386376 call_user_func ( ) ..\ServiceManager.php:737
15 0.1189 3386400 Zend\Mvc\Service\RequestFactory->createService( ) ..\ServiceManager.php:0
16 0.1235 3752048 Zend\Http\PhpEnvironment\Request->__construct( ) ..\RequestFactory.php:32
17 0.1244 3785552 Zend\Stdlib\Parameters->__construct( ) ..\Request.php:64
18 0.1244 3785800 Composer\Autoload\ClassLoader->loadClass( ) ..\ClassLoader.php:0
19 0.1253 3871440 include( '...\vendor\zendframework\zendframework\library\Zend\Stdlib\ArrayObject.php' ) ..\ClassLoader.php:183

Matthew Weier O'Phinney

@ZeinEddin That's even stranger, as it was probably more broken on 2.1.0.

Can you give me the following information so I can try and reproduce?

  • exact PHP version string as reported by the constant PHP_VERSION
  • your composer.json contents
  • if you've modified either init_autoloader.php or public/index.php, those details
  • If you're not using Composer for autoloading, let me know that, too (though if you're updating via Composer, this is unlikely)

I've tried installing a brand new project using zftool.phar and Composer via PHP 5.3.3, and each time I've done so, it has worked with 2.1.3.

Mohammad ZeinEddin

I tried a newer version of PHP and it worked... but it breaks on 5.3.3 (which is our server PHP version)!
I just downloaded the skeleton application with the same composer.json without any of my code, and it worked...

echo PHP_VERSION; => 5.3.3
composer.json contents:
{
"name": "...",
"description": "...",
"license": "...",
"keywords": [
"..."
],
"homepage": "...",
"repositories": [
{
"type": "composer",
"url": "https://packages.zendframework.com/"
}
],
"minimum-stability": "alpha",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.1.",
"zendframework/zendservice-recaptcha": "2.0.
",
"zendframework/zendpdf": "2.0.",
"doctrine/doctrine-module": "dev-master",
"doctrine/doctrine-orm-module": "0.
"
}
}
init_autoloader.php & public/index.php : not modified

Matthew Weier O'Phinney

@ZeinEddin Are you saying that installing a new app with 5.3.3 works for you?

If so, in your actual app, try removing the vendor directory and composer.lock file, and then running a composer install again; it may be that the update wasn't correctly occurring.

Mohammad ZeinEddin

Yes...
I will try to trace the error in my application to see if I am doing something wrong in my code...! if it wasn't my code I will tell you... thanks for your time... :)

Mohammad ZeinEddin

I don't know why is that happening, but I am writing this just in case someone faced the same problem as I did. I deleted the vendor directory and the composer.lock file and I did a new composer.phar install to zf 2.1.3 but didn't work... I noticed after comparing with a new project that the files autoload_real.php and init_autoloader.php has missing lines... and after I added them (specifically to autoload_real.php) everything worked fine...
the lines that was missing from autoload_real.php:
require $vendorDir . '/zendframework/zendframework/library/Zend/Stdlib/compatibility/autoload.php';
require $vendorDir . '/zendframework/zendframework/library/Zend/Session/compatibility/autoload.php';

the lines that was missing from init_autoloader.php:
require $zf2Path . '/Zend/Stdlib/compatibility/autoload.php';
require $zf2Path . '/Zend/Session/compatibility/autoload.php';

Deleted user Unknown referenced this pull request from a commit
Matthew Weier O'Phinney weierophinney [#3714] Fix issues with 5.3.3 polyfills
- When installing the entire framework, the `autoload.files` of
  `composer.json` are sorted alphabetically. This causes an issue, as
  the `Zend\Session` polyfill depends on the `Zend\Stdlib` polyfill.
- When installing the components separately, they are sorted based on
  dependencies, and thus the require statements happen in the correct
  order.
- The solution presented here is to test if (a) the polyfill class is
  already declared, and (b) if not, attempt to load the polyfill based
  on the known directory structure.
0ad3a59
Schneider95220 Schneider95220 referenced this pull request from a commit in Schneider95220/BlogMurVesperia
Matthew Weier O'Phinney weierophinney Add polyfill support for non-composer autoloading
- Ensure that if composer is not used for autoloading, polyfills are still
  required. See zendframework/zf2#3714 for details
bde459f
Schneider95220 Schneider95220 referenced this pull request from a commit in Schneider95220/BlogMurVesperia
Matthew Weier O'Phinney weierophinney Add polyfill support for non-composer autoloading
- Ensure that if composer is not used for autoloading, polyfills are still
  required. See zendframework/zf2#3714 for details
061b886
N3XT0R N3XT0R referenced this pull request from a commit in N3XT0R/TS3UI
Matthew Weier O'Phinney weierophinney Add polyfill support for non-composer autoloading
- Ensure that if composer is not used for autoloading, polyfills are still
  required. See zendframework/zf2#3714 for details
b8b0de0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 21, 2013
  1. Matthew Weier O'Phinney

    [#3714] Fix issues with 5.3.3 polyfills

    weierophinney authored
    - When installing the entire framework, the `autoload.files` of
      `composer.json` are sorted alphabetically. This causes an issue, as
      the `Zend\Session` polyfill depends on the `Zend\Stdlib` polyfill.
    - When installing the components separately, they are sorted based on
      dependencies, and thus the require statements happen in the correct
      order.
    - The solution presented here is to test if (a) the polyfill class is
      already declared, and (b) if not, attempt to load the polyfill based
      on the known directory structure.
This page is out of date. Refresh to see the latest.
6 library/Zend/Session/compatibility/autoload.php
View
@@ -1,5 +1,11 @@
<?php
if (version_compare(PHP_VERSION, '5.3.4', 'lt')) {
+ if (!class_exists('Zend\Stdlib\ArrayObject', false)
+ && file_exists(__DIR__ . '/../../Stdlib/compatibility/autoload.php')
Evan Coury Collaborator

Should this be is_readable()?

Matthew Weier O'Phinney Owner

Either one will work. Both do stat checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ ) {
+ require __DIR__ . '/../../Stdlib/compatibility/autoload.php';
+ }
+
require_once __DIR__ . '/Container.php';
require_once __DIR__ . '/Storage/SessionArrayStorage.php';
}
4 library/Zend/Stdlib/compatibility/autoload.php
View
@@ -1,4 +1,6 @@
<?php
-if (version_compare(PHP_VERSION, '5.3.4', 'lt')) {
+if (version_compare(PHP_VERSION, '5.3.4', 'lt')
+ && !class_exists('Zend\Stdlib\ArrayObject', false)
+) {
require_once __DIR__ . '/ArrayObject.php';
}
Something went wrong with that request. Please try again.