php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25329 sqlite_create_function with method and reference to $this
Submitted: 2003-08-31 00:00 UTC Modified: 2003-12-27 17:17 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: firepages at firepages dot com dot au Assigned: helly
Status: Closed Package: SQLite related
PHP Version: 5.0.0b3-dev, 4.3.4 OS: *
Private report: No CVE-ID:
 [2003-08-31 00:00 UTC] firepages at firepages dot com dot au
Description:
------------
when trying to use sqlite_create_function() & passing a class method of $this apache dies orribly (appreciate it may be an apache issue)

Win XP Pro / php 4.3.3 compiled (MSVC) against apache 2.0.47

eg 
sqlite_create_function($this->db, 'link_keywords', array( $this,'linkers' ) , 1);
/*OR*/
sqlite_create_function($this->db, 'link_keywords', array( &$this,'linkers' ) , 1);

note that calling an external class method or normal function [array($ext_class,$method)]gives no problem , just methods of $this

not tested on apache 1.* 



Reproduce code:
---------------
class sqlite_help{
	function sqlite_help(){
		$this->db = sqlite_open('e:/phpdev/cp/my_admin.sqldb.eng', 0666, $sqliteerror);
		sqlite_create_function($this->db, 'link_keywords', array( $this , 'linkers') , 1);
		return $this->db;
	}
	function get_single( $key ){
		$res = sqlite_query( $this->db,"SELECT link_keywords(var) FROM my_admin WHERE key = '$key'" );
		$r = sqlite_fetch_array( $res , SQLITE_NUM );
		return $r[0];
	}
	function linkers( $str ){
		$keywords = array('phpmyadmin'=>'<a href="http://localhost/phpmyadmin/index.php"">phpMyAdmin</a>');
		foreach($keywords as $k=>$v){$str = str_replace( $k , $v , $str );}
		return nl2br( $str );
	}
}
$yaks=new sqlite_help();
echo $yaks->get_single('general');

Expected result:
----------------
str_replaced data from DB

works if function is external or external class method

Actual result:
--------------
an MS 'Apache has encountered an ....' etc Dialog no apache error log available , no PHP error logged.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-31 03:30 UTC] sniper@php.net
PECL_4_3:

/usr/src/web/php/php4_3/Zend/zend_hash.c(544) : ht=0x08212634 is being destroyed
/usr/src/web/php/php4_3/Zend/zend_hash.c(108) : Bailed out without a bailout address!

HEAD:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (runnable)]
_efree (ptr=0x0) at /usr/src/web/php/php5/Zend/zend_alloc.c:257
257             CALCULATE_REAL_SIZE_AND_CACHE_INDEX(p->size);
(gdb) bt
#0  _efree (ptr=0x0) at /usr/src/web/php/php5/Zend/zend_alloc.c:257
#1  0x816cdfb in _zval_ptr_dtor (zval_ptr=0x4029bac4) at /usr/src/web/php/php5/Zend/zend_execute.h:67
#2  0x80b80c2 in php_sqlite_callback_invalidator (funcs=0x4029babc) at /usr/src/web/php/php5/ext/sqlite/sqlite.c:288
#3  0x80b8110 in php_sqlite_callback_dtor (pDest=0x4029babc) at /usr/src/web/php/php5/ext/sqlite/sqlite.c:310
#4  0x817a738 in zend_hash_destroy (ht=0x4029b8ec) at /usr/src/web/php/php5/Zend/zend_hash.c:513
#5  0x80b813c in php_sqlite_db_dtor (rsrc=0x4029b95c) at /usr/src/web/php/php5/ext/sqlite/sqlite.c:321
#6  0x817bb4d in list_entry_destructor (ptr=0x4029b95c) at /usr/src/web/php/php5/Zend/zend_list.c:178
#7  0x817a89e in zend_hash_apply_deleter (ht=0x8349f10, p=0x4029b924) at /usr/src/web/php/php5/Zend/zend_hash.c:568
#8  0x817a9da in zend_hash_graceful_reverse_destroy (ht=0x8349f10) at /usr/src/web/php/php5/Zend/zend_hash.c:634
#9  0x817bc56 in zend_destroy_rsrc_list (ht=0x8349f10) at /usr/src/web/php/php5/Zend/zend_list.c:234
#10 0x816cc93 in shutdown_executor () at /usr/src/web/php/php5/Zend/zend_execute_API.c:279
#11 0x817555f in zend_deactivate () at /usr/src/web/php/php5/Zend/zend.c:795
#12 0x8149224 in php_request_shutdown (dummy=0x0) at /usr/src/web/php/php5/main/main.c:1197
#13 0x81ab61e in main (argc=2, argv=0xbffff694) at /usr/src/web/php/php5/sapi/cli/php_cli.c:1013
#14 0x401b19cb in __libc_start_main (main=0x81aa848 <main>, argc=2, argv=0xbffff694, init=0x8070368 <_init>, 
    fini=0x81abbe4 <_fini>, rtld_fini=0x4000aea0 <_dl_fini>, stack_end=0xbffff68c)
    at ../sysdeps/generic/libc-start.c:92

 [2003-12-27 16:56 UTC] helly@php.net
The problem is the reference to $this from the generated sqlite (php)function. See ext/sqlite/tests/sqlite_oo_029.phpt on how to work around.
 [2003-12-27 17:17 UTC] helly@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 01:01:56 2014 UTC