|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-02-23 03:23 UTC] mfischer@php.net
Description:
------------
Under certain circumstances the "enchant dict" resource variable may loose it's type information. In my testing this seems to be related to whether the "enchant broker" resource is in the same scope or not.
(I've tested with xdebug disable too, there was no change, just to be sure).
The example shows the problem:
<?php
class foo {
private $enchant;
private $dict;
public function __construct() {
$enchant = enchant_broker_init();
$this->dict = enchant_broker_request_dict($enchant, 'en');
var_dump($this->enchant, $this->dict);
}
public function getSuggestions($sWord) {
var_dump($this->dict);
return enchant_dict_suggest($this->dict, $sWord);
}
}
$f = new foo;
$f->getSuggestions("soong");
?>
:!php problem_oop.php
NULL
resource(5) of type (enchant dict)
resource(5) of type (Unknown)
Warning: enchant_dict_suggest(): 5 is not a valid enchant dict resource in /data/users/markus/src/enchant/problem_oop.php on line 12
Call Stack:
0.0002 58452 1. {main}() /data/users/markus/src/enchant/problem_oop.php:0
0.0081 59444 2. foo->getSuggestions() /data/users/markus/src/enchant/problem_oop.php:16
0.0081 59444 3. enchant_dict_suggest() /data/users/markus/src/enchant/problem_oop.php:12
When I change the broker resource to be a property of the object, the dict resource survives and it works.
<?php
class foo {
private $enchant;
private $dict;
public function __construct() {
$this->enchant = enchant_broker_init();
$this->dict = enchant_broker_request_dict($this->enchant, 'en');
var_dump($this->enchant, $this->dict);
}
public function getSuggestions($sWord) {
var_dump($this->dict);
return enchant_dict_suggest($this->dict, $sWord);
}
}
$f = new foo;
$f->getSuggestions("soong");
?>
:!php problem_oop.php
resource(4) of type (enchant broker)
resource(5) of type (enchant dict)
resource(5) of type (enchant dict)
It is not related to OOP, this is just how I discovered the bug, see this example too:
<?php
function get_dict() {
$rBroker = enchant_broker_init();
return enchant_broker_request_dict($rBroker, 'en');
}
$rDict = get_dict();
enchant_dict_suggest($rDict, "soong");
?>
:!php problem.php
Warning: enchant_dict_suggest(): 5 is not a valid enchant dict resource in /data/users/markus/src/enchant/problem.php on line 7
Call Stack:
0.0002 53708 1. {main}() /data/users/markus/src/enchant/problem.php:0
0.0080 54084 2. enchant_dict_suggest() /data/users/markus/src/enchant/problem.php:7
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 19:00:01 2025 UTC |
Good catch and I wonder where is the problem. Given that the following code: function get_broker() { $t = enchant_broker_init(); var_dump($t); return $t; } $rbroker = get_broker(); var_dump($rbroker); function get_dict($broker) { $t = enchant_broker_request_dict($broker, 'en'); var_dump($t); return $t; } $rDict = get_dict($rbroker); var_dump($rDict); simply works, it looks like something really not obvious. I will run some more tests and trace the execution. Ilia? Maybe you have an idea?