For quite a while I have been fighting with what I believe to be a bug in
the Zend Engine 2.
In PHPUnit2 I have the following code:
public function run(PHPUnit2_Framework_Test $test) {
// $test->name: string(14) "testGetBalance"
$this->startTest($test);
try {
// $test->name: string(14) "testGetBalance"
$test->runBare();
}
catch (PHPUnit2_Framework_AssertionFailedError $e) {
// $test->name: string(14) "testgetbalance"
$this->addFailure($test, $e);
}
catch (Exception $e) {
// $test->name: string(14) "testgetbalance"
$this->addError($test, $e);
}
// $test->name: string(14) "testgetbalance"
$this->endTest($test);
}
The object referenced by the variable $test has a private attribute
called "name". The value of this attribute somehow get lowercased
when the object is used inside the catch-block.
My effort to come up with a small, reproducing script for this issue
has yet to bear fruit as the obvious approach
<?php
class Foo {
private $bar = 'BAR';
}
class Bar {
public function doSomething(Foo $foo) {
var_dump($foo);
try {
var_dump($foo);
throw new Exception('...');
}
catch (Exception $e) {
var_dump($foo);
}
var_dump($foo);
}
}
$f = new Foo;
$b = new Bar;
$b->doSomething($f);
?>
does not show the problem.
Any idea what I might be missing here? Is there some way to debug the
engine to see where the lowercasing happens?
Thanks!
--
Sebastian Bergmann http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69
Hello Sebastian,
Wednesday, September 22, 2004, 9:52:18 PM, you wrote:
For quite a while I have been fighting with what I believe to be a bug in
the Zend Engine 2.
In PHPUnit2 I have the following code:
public function run(PHPUnit2_Framework_Test $test) {
// $test->name: string(14) "testGetBalance"
$this->startTest($test);
try { // $test->name: string(14) "testGetBalance" $test->runBare(); }
catch (PHPUnit2_Framework_AssertionFailedError $e) { // $test->name: string(14) "testgetbalance" $this->addFailure($test, $e); }
catch (Exception $e) { // $test->name: string(14) "testgetbalance" $this->addError($test, $e); }
// $test->name: string(14) "testgetbalance" $this->endTest($test);
}
The object referenced by the variable $test has a private attribute
called "name". The value of this attribute somehow get lowercased
when the object is used inside the catch-block.
My effort to come up with a small, reproducing script for this issue
has yet to bear fruit as the obvious approach
<?php
class Foo {
private $bar = 'BAR';
}
class Bar {
public function doSomething(Foo $foo) {
var_dump($foo);
try { var_dump($foo); throw new Exception('...'); }
catch (Exception $e) { var_dump($foo); }
var_dump($foo); }
}
$f = new Foo;
$b = new Bar;
$b->doSomething($f);
?>
does not show the problem.
Any idea what I might be missing here? Is there some way to debug the
engine to see where the lowercasing happens?
Thanks!
--
Sebastian Bergmann http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69
Disallow inlining and set a breakpoint on zend_str_tolower_copy() is most
likely responsible for downcasing if the engine is the problem....
Best regards,
Marcus mailto:helly@php.net
Sebastian Bergmann wrote:
In PHPUnit2 I have the following code:
It seems that I have been at slightly the wrong code
try {
$class = new ReflectionClass($this);
var_dump($this);
$method = $class->getMethod($this->name);
var_dump($this);
exit;
}
object(BankAccountTest)#38 (2) {
["codeCoverageInformation:private"]=>
array(0) {
}
["name:private"]=>
string(14) "testGetBalance"
}
object(BankAccountTest)#38 (2) {
["codeCoverageInformation:private"]=>
array(0) {
}
["name:private"]=>
string(14) "testgetbalance"
}
So it looks like calling getMethod() on a ReflectionClass object for
the current object lowercases the contents of the variable that is
passed to it.
Hardcoding the getMethod() parameter prevents the lowercasing
try {
$class = new ReflectionClass($this);
var_dump($this);
$method = $class->getMethod('testGetBalance');
var_dump($this);
exit;
}
object(BankAccountTest)#38 (2) {
["codeCoverageInformation:private"]=>
array(0) {
}
["name:private"]=>
string(14) "testGetBalance"
}
object(BankAccountTest)#38 (2) {
["codeCoverageInformation:private"]=>
array(0) {
}
["name:private"]=>
string(14) "testGetBalance"
}
while copying the value from $this->name to $name and passing that to
getMethod() does not
try {
$class = new ReflectionClass($this);
var_dump($this);
$name = $this->name;
$method = $class->getMethod($name);
var_dump($this);
exit;
}
object(BankAccountTest)#38 (2) {
["codeCoverageInformation:private"]=>
array(0) {
}
["name:private"]=>
string(14) "testGetBalance"
}
object(BankAccountTest)#38 (2) {
["codeCoverageInformation:private"]=>
array(0) {
}
["name:private"]=>
string(14) "testgetbalance"
}
Sorry for these lengthy mails but this issue is important to me as it
hinders the development of PHPUnit2.
--
Sebastian Bergmann http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69
Sebastian Bergmann wrote:
Sorry for these lengthy mails but this issue is important to me as it
hinders the development of PHPUnit2.
Since I was finally able to write a small reproducing script I opened a
bug report for this: http://bugs.php.net/bug.php?id=30209
--
Sebastian Bergmann http://www.sebastian-bergmann.de/
GnuPG Key: 0xB85B5D69 / 27A7 2B14 09E4 98CD 6277 0E5B 6867 C514 B85B 5D69