Re: Hashtables

From: Date: Sat, 30 Nov 2002 18:30:54 +0000
Subject: Re: Hashtables
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-91962@lists.php.net to get a copy of this message
On Sat, 30 Nov 2002, John Coggeshall wrote: > > Hey all > > I was playing around and I'm running into a problem with a hashtable... > Basically, it's segfaulting my code :) Specifically, I'm trying to > return the number of items in the hash... > > if(zend_hash_num_elements(hash) == 0) > > Which causes the following: > > Program received signal SIGSEGV, Segmentation fault. > zend_hash_num_elements (ht=0x0) at /home/php/php4/Zend/zend_hash.c:988 > 988 return ht->nNumOfElements; You need to check if your ht actually is initialized, at the moment it is NULL, and if you want to dereference that, you get a segfault. if (!hash || (zend_hash_num_elements(hash) == 0)) { } should work. Derick -- ------------------------------------------------------------------------- Derick Rethans http://derickrethans.nl/ PHP Magazine - PHP Magazine for Professionals http://php-mag.net/ -------------------------------------------------------------------------

« previous php.dev (#91962) next »