Strange php behaviour on a gd function
i met a very strange PHP behaviour, i don't understand why it behaves like this. I'm using the imagesetbrush function in this way:
class foo
{
function setbrush($image)
{
//$this->_resource contains the main image resource
imagesetbrush($this->_resource, $image);
}
}
...
$res=imagecreatefrompng("image.png");
$class->setbrush($开发者_StackOverflow社区res);
in this way it works, but if i change the code like this:
class foo
{
function setbrush($image)
{
$res=imagecreatefrompng($image);
imagesetbrush($this->_resource, $res);
}
}
...
$class->setbrush("image.png");
it doesn't work anymore. Do you see some error? It doesn't show me any message it simply doesn't execute the function.
Could it be that the reference to the variable $res disappears after the function call? Have you tried declaring it as a class variable, just like the $_resource variable?
Maybe somewhere in your foo class the working directory changes, so it can no longer find the image.png maybe when opening //$this->_resource contains the main image resource
精彩评论