Bug #70208 [NEW]: Assert breaking access on objects

From: Date: Fri, 07 Aug 2015 18:31:26 +0000
Subject: Bug #70208 [NEW]: Assert breaking access on objects
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195005@lists.php.net to get a copy of this message
From:             neclimdul at gmail dot com
Operating system: linux
PHP version:      7.0Git-2015-08-07 (Git)
Package:          Class/Object related
Bug Type:         Bug
Bug description:Assert breaking access on objects

Description:
------------
Recently some code adding assertions to code in Drupal caused some
really weird failures when running tests. It seems you need a couple
things to trigger this.

1) You have an object stored on a property
2) You call an assert that calls a method on an argument.
3) You reference the protected property after that assertion.


Test script:
---------------
<?php

class class1 {
  protected $prop;
  public function __construct($prop) { $this->prop = $prop; }
  public function getThing($arg) {
    assert('$arg->isValid();');
    $this->prop->method();
  }
}

class class2 {
  public function method() { echo "here\n"; }
}

class class3 {
  public function isValid() { return false; }
}

$tmp = new class1(new class2());
$tmp->getThing(new class3());

Expected result:
----------------
the script outputs "here"

Actual result:
--------------
PHP Fatal error:  Uncaught Error: Cannot access protected property
class1::$prop in
/home/jgilliland/public_html/d8_1/assert_protected_property.txt:8
Stack trace:
#0 /home/jgilliland/public_html/d8_1/assert_protected_property.txt(21):
class1->getThing(Object(class3))
#1 {main}
  thrown in
/home/jgilliland/public_html/d8_1/assert_protected_property.txt on line
8


-- 
Edit bug report at https://bugs.php.net/bug.php?id=70208&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=70208&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=70208&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=70208&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=70208&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=70208&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=70208&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=70208&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=70208&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=70208&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=70208&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=70208&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=70208&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=70208&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70208&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=70208&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=70208&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=70208&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70208&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=70208&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=70208&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#195005) next »