php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70208 Assert breaking access on objects
Submitted: 2015-08-07 18:31 UTC Modified: 2015-08-07 21:57 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: neclimdul at gmail dot com Assigned:
Status: Closed Package: Class/Object related
PHP Version: 7.0Git-2015-08-07 (Git) OS: linux
Private report: No CVE-ID:
 [2015-08-07 18:31 UTC] neclimdul at gmail dot com
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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-07 18:54 UTC] lucashedding at gmail dot com
Cross posting with the d.o. issue link: https://www.drupal.org/node/2547715
 [2015-08-07 21:57 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2015-08-07 21:57 UTC] cmb@php.net
<http://3v4l.org/7cQNm> confirms the behavior.
 [2015-08-07 22:02 UTC] bwoebi@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b7aac1f5f2d1f072fa52b0bbedce1ac7d20ae789
Log: Fixed bug #70208 (Assert breaking access on objects)
 [2015-08-07 22:02 UTC] bwoebi@php.net
-Status: Verified +Status: Closed
 [2015-08-18 16:24 UTC] ab@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b7aac1f5f2d1f072fa52b0bbedce1ac7d20ae789
Log: Fixed bug #70208 (Assert breaking access on objects)
 [2016-07-20 11:37 UTC] davey@php.net
Automatic comment on behalf of bobwei9@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b7aac1f5f2d1f072fa52b0bbedce1ac7d20ae789
Log: Fixed bug #70208 (Assert breaking access on objects)
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Feb 28 14:01:40 2017 UTC