|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-07-16 19:00 UTC] nologic at pchome dot com dot tw
Description: ------------ apache_2.0.47-win32-x86-no_ssl XOOPS203 ( http://www.xoops.org ) For install: php5-win32-200307162230 => Fatal Error ! php4.3.2 => succeeded ! sorry...my English is poor. Reproduce code: --------------- class TextSanitizer { function &htmlSpecialChars($text) { line 96 -> return preg_replace("/&/i", '&', htmlspecialchars($text, ENT_QUOTES)); } } Expected result: ---------------- Fatal error: Only variables or references can be returned by reference in D:\www\xoops2\html\install\class\textsanitizer.php on line 96 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 21:00:01 2025 UTC |
If you do it like this it works: class TextSanitizer { function &htmlSpecialChars($text) { $foo = preg_replace("/&/i", '&', htmlspecialchars($text, ENT_QUOTES)); return $foo; } } So would it really be *that* hard to make it work?I agree with Zeev on this one, this shouldn't be fixed. People will need to learn to write good code one day or the other, and returning a reference like that is VERY bad practice (try to do that in C++!). Even returning a reference to a local variable like this example should produce an error : class foo { function &bar() { $whatever = 5; return $whatever; } } because $whatever should not exist anymore after function bar return (according to correct scope rules), thus this reference is not referencing anything anymore... Instead of always asking to fix bad programming practice people should learn the correct way to do it. This is my opinion.and this? Fatal error: Only variables or references can be returned by reference in /usr/lib/php/DB/common.php on line 766 function &query($query, $params = array()) { if (sizeof($params) > 0) { $sth = $this->prepare($query); if (DB::isError($sth)) { return $sth; } $ret = $this->execute($sth, $params); $this->freePrepared($sth); return $ret; } else { $result = $this->simpleQuery($query); if (DB::isError($result) || $result === DB_OK) { return $result; } else { -->766 return new DB_result($this, $result); } } } running on Apache/2.0.48 (Trustix Secure Linux/Linux) PHP/5.0.0b2This bug pretty much rules out backwards compatibility with most php4 OOP programs. It's quite silly to say that returning a reference by calling another function that returns a reference is "bad" programing practice. And by the way, C++ has no problem with returning pointers. Just to be clear: function &getHomeTeam() { return $this->getTeam(TEAM_TYPE_HOME); } Really should work.