New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Declaration of CCookieCollection::add() should be compatible with that of CMap::add() #1087
Comments
Also, the declaration of CCookieCollection::remove() is wrong and it'll result in a fatal error. |
Which PHP version are you using? |
Apache/2.2.21 (Win32) mod_python/3.3.1 Python/2.5.4 PHP/5.2.17 Yii Framework/1.1.11 Sorry for not posting this, i was in a hurry when i posted the issue. |
Thanks. Do you know what is wrong with remove()? |
well, about remove, as long as the method declaration is not the same as the parent implementation, i can only assume it will result in a fatal error when the method is called. |
seems when error_reporting is E_STRICT it is not allowed to overide a method and change default values for parameters. |
Did you actually try it? PHP only checks the number of required parameters. |
See also this behavior: seems you can add params, but not remove any: |
Atleast here with php 5.4-latest with E_ALL I don't see any warnings or errors, aslong as I don't remove or add any params. |
add() is definitely problematic, but not remove() I think. |
problem introduced in d3b0bc0, and yes, remove shouldn't be a problem. |
I'm wondering if this will cause problem as long as the CHttpRequest.php file is included. If so, this is a big issue and we should fix it asap. |
@qiangxue it only occurs, when you are trying to call the method. |
Even if I can't reproduce this with 5.4(E_ALL) and 5.3(E_ALL | E_STRICT). I see two options: Back out that change or change the signature of CMap::add(). I'm not sure what would be better, but setting second param of CMap::add() to null shouldn't brake code, as it should have been called with all params set prior to this change. Also this should not brake ArrayAccess, as offsetSet is still requiring two params. Also this would allow users to override CMap::add in simliar way as it is done in CCookieCollection, which could be quite usefull in some scenarios. |
No, we should definitely not change CMap::add() because it would break other child classes if they override this method. |
original issue that introduced this "problem" - #120 |
@qiangxue <?php
// E_STRICT included in E_ALL in PHP 5.4
error_reporting(E_ALL);
class t{
public function add($name, $value = null){
return $name;
}
}
class tt extends t{
public function add($name,$value){
return parent::add($name).$value;
}
}
$tt = new tt;
var_dump($tt->add('Name ', 'Value')); // string(10) "Name Value"
$t = new t;
var_dump($t->add('Name2')); // string(5) "Name2" |
@suralc - try with error_reporting(-1) |
PHP 5.3 seems to be fine, but I was able to reproduce the problem in 5.2. |
@twisted1919 @qiangxue
|
@suralc well, it's obviously a 5.2.x problem then, and as long as Yii 1.1.x branch is targeted to 5.2.x this will cause allot of issues :) |
@twisted1919 I opened #1091 and #1092 to solve this. Do you have a better solution to fix this issue? I'd go with someting like (I got to this after I opend the pr, so I let them open, but presenteing this to discussion) <?php
function add($cookie, $cookieObject)
{
if($cookie instanceof CHttpCookie)
//ignore second paramterer, but be sure that it was set
} |
@suralc Anyway, in the future, tests should be made on multiple php version (5.2.x/5.3.x branches) with strict error reporting so that we can avoid things like this. |
Well, this was added before travis support was there. I'd go for the solution I posted above, this would fix the issue, and would only mean to introduce a minor bc issue (which most will not notice, as 1.1.11 is young) |
I reviewed your PR's. I think it's better we simply revert the whole changeset. |
Sadly, it would still eleminate the issue of mismatching the names, even if this is something that just should not happen. I'll reopen #1091. Changelog and update should be adjusted I guess. |
Closing this issue as @qiangxue already merged the #1091 Unfortunately PHP5.1 restricts this solution and there is no other way to solve the "send name only once" in addition makes no sense to have a second parameter that can be anything (#1093). Only solution that makes sense is to revert the change. |
After a fresh update to 1.1.11 i get the following error when trying to login:
Seems the problem is of course in CCookieCollection::add() method, which currently looks like:
but changing its declaration to
seems to fix the issue.
However, i don't really know the other implications if changing the method declaration, maybe it'll break other classes.
The text was updated successfully, but these errors were encountered: