This has got to be one of the strangest errors I have error come across jsut because the exact same code on two other systems work fine.
Let me explain my set up and how and where it works. First of all I am using zend framework and the error is thrown in the Zend/View/Abstract class on line 300.
Windows system running PHP 5.3.3 - Works Fine Here. Linux Centos 5.5 system running PHP 5.3.3 - Works Fine here. Linux Centos 5.5 system running PHP 5.3.6 - This system gives me the fatal error.
PHP - Fatal error: Cannot access property started with '\0'
Looking at the setup I first thought that this had to be a bug in PHP but I am not so sure. I first had PHP 5.3.5 installed and upgraded to 5.3.6 but that didnt help.
The code throwing the error should work also so I am completely confused as to why I am getting the error on this system and not the other two.
Code that is throwing the error is :
$this->$key = $val;
Located in the following method:
public function __set($key, $val)
{
if ('_' != substr($key, 0, 1)) {
$this->$key = $val;
return;
}
require_once 'Zend/View/Exception.php';
$e = new Zend_View_Exception('Setting private or protected class members is not allowed');
$e->setView($this);
throw $e;
}
Any help would be greatly appreciated.
I did some further debugging and it isn't one of my variables causing the error. I found that when the $key variable was set to Zend_View_useViewStream the fatal error is thrown, so I vardumped it before and after it was string trimmed.
KEY string(25) "Zend_View_useViewStream"
TRIMMED string(24) "Zend_View_useViewStream"
As you can see the string lenght is 1 character longer when the variable is not trimmed but they seem identical to me?? I guess the nul-byte [ "\0" (ASCII 0 (0x00)), the NUL-byte. ] is being stripped with trim but why is it being added on this system and not the others?
__set() is a Magic Method that's called when you try and set a property that doesn't exist. If it's throwing an error in Zend_View_Abstract then one of your views is trying to set an instance property that doesn't exist, and the instance property begins with a null character.
$this->$property = $value;
You could try and trim the property
$property = trim($property);
$this->$property = $value;
I have a feeling that something is attempting to modify $this erroneously. Can you track down the code in your view?
I would have said it's a locale-thing again. But appearantly this has been cemented in current PHP versions:
if (Z_STRVAL_P(member)[0] == '\0') {
if (!silent) {
if (Z_STRLEN_P(member) == 0) {
zend_error(E_ERROR, "Cannot access empty property");
} else {
zend_error(E_ERROR, "Cannot access property started with '\\0'");
}
}
return NULL;
So we can conclue this was introduced somewhen around PHP 5.3.3 to 5.3.6. (My version is 5.3.2, same effect, but probably a backported patch). Cannot find anything what indicates the reason in the changelog.
Anyway, you cannot use binary property names then if you don't ensure they don't start with NUL.
--
The change occured between PHP 5.0.0 and PHP 5.1.0 already:
And I'm suspecting this is the reason:
if (prop_info_name[0] == '\0' && prop_info_name[1] != '*' && !(property_info->flags & ZEND_ACC_PRIVATE)) {
/* we we're looking for a private prop but found a non private one of the same name */
return FAILURE;
}
I haven't looked this through, but from that snippet I assume the \0 byte was used for something different originally and got then forbidden later on ..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With