Opened 23 years ago

Closed 23 years ago

#23 closed defect (fixed)

PHP MapScript ms_newMapObj() with empty map doesn't work

Reported by: dmorissette Owned by: dmorissette
Priority: high Milestone:
Component: MapScript-PHP Version: 3.5
Severity: normal Keywords:
Cc:

Description

Problem reported by Rob Martinson on 2001-07-02:

I'm attempting to load layers from a database on an empty map object.
This way I can control all of the maps from a database without writing
out a new .map file for each change. Currently I'm trying:

dl("php_mapscript.so");
$map = ms_newMapObj('');
$map->set("width",400);
$map->set("height",300);
$map->set("shapepath","/path/to/my/data");

$layer = ms_newLayerObj($map);
$layer->set("name","county");
$layer->set("type",POLYGON);
$layer->set("status",MS_ON);
$layer->set("data","ctybdpy");

$img = $map->draw();   <--at this point I get an error stating "Object
has an invalid _handle_ property"

The same small script and data work if I load the layers through a .map
file using the same paths with:

dl("php_mapscript.so");

$map = ms_newMapObj("demo2.map");
$img = $map->draw();

I'm sure someone else has done something similar. Any pointers?

Change History (6)

comment:1 by dmorissette, 23 years ago

> From: owner-mapserver-users@lists.gis.umn.edu 
> [mailto:owner-mapserver-users@lists.gis.umn.edu] On Behalf Of 
> Vladimir Guzmán
> Sent: Thursday, July 12, 2001 11:50 PM
> To: mapserver-users@lists.gis.umn.edu
> Subject: [mapserver-users] getlayer
> 
> 
> Hello.
> Please, if someone can help me.
> I've got an error when I try to get a layer object, it seems 
> that the first time i use the method it works fine, but the 
> next time the object map is kind of corrupted, so I get the error : 
> "Fatal error:  Object has an invalid _handle_ property in 
> /usr/local/httpd/htdocs/mapserver/test_draw_map.phtml on line 
> 47" I'm working with php, and I have the same error in the 
> example map gmap. The only way I currently make it work is: 
> every time i call getlayer() I use the instruction: $map = 
> ms_newMapObj("demo.map"); But this is not the correct 
> solution. ¿suggestions?
> 
> Thank you,
> 
> Vladimir G
> 

comment:2 by dmorissette, 23 years ago

Another confirmation of this and to expand on my earlier problem about
using dynamic maps...

I am unable to add any new layer to any new or existing map via
PHP/Mapscript. In short, if I create a layer using $layer =
ms_newlayerobj($mapObj); on a map object using a new or existing map, no
matter the number of or lack of properties and/or classes I set for the
layer, the next call to ANY sub object, property, or method of the
mapobject fails with "Object has an invalid _handle_ property. 

This has been listed in the MapServer bugs database by Daniel
Morissette, but I thought I would expand on the problem here.

Rob Martinson

comment:3 by dmorissette, 23 years ago

From Vladimir G.:

My system configuration is:

SUSE linux 6.4.
Mapserver version: 3.4
PHP version: 4.06
Apache version: 1.3.12

The mapserver configure command is:

./configure --with-gd=/root/Desktop/programas/gd-1.8.4/
--with-php=/root/Desktop/programas/php-4.0.6 --with-apxs --with-sde
--with-jpeg --with-ttf

The php configure command is:

./configure --with-dbase=yes --with-system-regex
--with-jpeg-dir=/root/Desktop/programas/jpeg-6b
--with-png-dir=/root/Desktop/programas/libpng/ --with-swf=yes
--with-pgsql=/usr/lib/pgsql --with-mysql=yes --with-gd=yes
--with-zlib=yes --with-xml --with-yp --with-ftp --with-snmp
--with-config-file-path=/etc/httpd --with-apxs=/usr/sbin/apxs
--with-exec-dir=/usr/lib/apache/bin --enable-versioning
--enable-track-vars --enable-magic-quotes --enable-safe-mode
--enable-sysvsem --enable-sysvshm --enable-thread-safety
i386-suse-linux-gnu


comment:4 by dmorissette, 23 years ago

Status: newassigned, assefa@dmsolutions.ca

comment:5 by dmorissette, 23 years ago

From Rob Martinson:

Thank you thank you! Consider this a confirmation to problems with PHP
4.0.6. I backtracked and rebuilt with source from 4.0.5 and I have zero
problems! The issues with losing the handle of the map when dynamically
generating a map from database contents are gone. I can now reliably (it
seems) create a map on a blank .map file using mapscript only to set
map/layer/class properties and add additional layers.

This works now with the CVS version of Mapserver, Gdal and PHP 4.0.5 on
my end.


comment:6 by dmorissette, 23 years ago

Resolution: fixed
Status: assignedclosed
The problem was that we have resource member vars (the _handle_ property), but 
we didn't increment the refcount on the resource that we were referring to.  So 
the resource referred to was getting deleted even if some objects were still 
referring to it.

The fix was to add a zend_list_addref(res_id) everytime we set a resource member 
variable in an object.

The reason why the problem happens only with PHP4.0.6 is that when a resource 
member variable in an object is deleted in PHP4.0.6 the list destructor is 
called but *it was not* in previous version of PHP, which resulted in memory 
leaks before.

Things seem to be working fine now with PHP 4.0.6 and with previous versions 
(but we may be leaking memory with 4.0.5 and older versions though).
Note: See TracTickets for help on using tickets.