comment posting fixed and warning removed, and why I don't mess with getter/setter
Comments
Display comments as
(Linear | Threaded)
|
December '08 | |||||
| Mon | Tue | Wed | Thu | Fri | Sat | Sun |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
| 29 | 30 | 31 | ||||
5.2.0
5.2.7
antispam
apache2
binary
cartoon
cgi
conference
Dotclear
dotclear2
fastcgi
feed
filter
filters
GD
google
graphics
htaccess
htscanner
iis
innotek
internals
ipc
ISP
libGD
lighttpd
Mysql
PEAR
PECL
PHP
PHP-core
php 5.2.7
png
qa
release
security
Sun
symfony
tutorial
virtualbox
virtualization
visual-C
win32
windows
wtf
zip
ziparchive
Posted by Pierre in
Uncategorized
Tuesday, November 28. 2006
During my upgrade to dotclear2, I noticed some notices about ""Indirect modification of overloaded property" and thought they are minor (notices…) and can be somehow ignored, bad idea ![]()
It seems that the known issues with setter/getters with array are more serious than I thought, being not really a fan of these magic methods, especially not for arrays or other non scalar data, I did not really "care", selber schuld ![]()
In the case of dotclear, the workaround is relatively easy:
<br /> class context<br /> { public $stack = array();</p> public function __set($name,$var) { $this->stack[$name] = $var; } public function __get($name) { if (!isset($this->stack[$name])) { return null; } return $this->stack[$name]; } } <p>$ctx = new context;<br /> $ctx->comment_preview = array();<br /> $ctx->comment_preview[‘content’] = ‘’;<br /> $ctx->comment_preview[‘rawcontent’] = ‘’;<br /> $ctx->comment_preview[‘name’] = ‘’;<br /> $ctx->comment_preview[‘mail’] = ‘’;<br /> $ctx->comment_preview[‘site’] = ‘’;<br /> $ctx->comment_preview[‘preview’] = false;<br /> $ctx->comment_preview[‘remember’] = false;<br /> var_dump($ctx);</p> <p>$comment_preview = array();<br /> $comment_preview[‘content’] = ‘’;<br /> $comment_preview[‘rawcontent’] = ‘’;<br /> $comment_preview[‘name’] = ‘’;<br /> $comment_preview[‘mail’] = ‘’;<br /> $comment_preview[‘site’] = ‘’;<br /> $comment_preview[‘preview’] = false;<br /> $comment_preview[‘remember’] = false;<br /> $ctx->comment_preview = $comment_preview;<br /> var_dump($ctx);<br />
The first initialiation will raise notices and fails (do not assign anything, as the error message says), the second works like a charm. This bug just confirms what I think about all these magic methods, don’t use them for non scalar unless someone put a gun on you.
The issue is known (thanks tony for the info). It is certainly due to the read/write access required by the array element change, but I do not know exactly how userland getter/setter work. I reopen an old bug (#36214), let see what will come out of it.
Olivier - #1 - 2006-11-28 09:23 - (Reply)
Hi, this bug was fixed in Dotclear 2 beta 3.1. The workaround consists to use ArrayObject instead of array in this particular case.
Pierre - #2 - 2006-11-28 13:36 - (Reply)
Hi Olivier, I use beta 3.1, the code I used as example here is from this version. Here is a little patch:http://blog.thepimp.net/misc/dotclear2b31_php52_fixes.txtIt fixes the comment preview and submission and silent two notices (yes, the comments /**/ can be droped
. Are you sometimes on freenode? I have to find back my login for your forum to post a bug ![]()
Pierre - #3 - 2006-11-28 14:34 - (Reply)
Ok, ArrayObject is used in trunc. Also note that I consider this issue as a php bug not really a dotclear one. Also the problem with ArrayObject is that it can be disabled with —disable-all, just like most of SPL...
Olivier - #4 - 2006-11-28 15:18 - (Reply)
You’re right, SPL is needed and I think that PHP 5 without SPL is not PHP 5
I’ll add the SPL test.