Opened 23 years ago

Closed 23 years ago

Last modified 23 years ago

#30 closed defect (fixed)

PHP_MAPSCRIPT - the infamous 'invalid _map_handle_' strikes again

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

Description

Date:         Wed, 8 Aug 2001 14:26:06 -0400 (CLT)
   From:         "Vinko Vrsalovic B." <v@w.cl>
     To:         morissette@dmsolutions.ca (Daniel Morissette)
    CC:         mapserver-users@lists.gis.umn.edu

Well, I finally got the time to upgrade from PHP4.0.3 to PHP 4.0.6.

I'm using the latest CVS build of MS3.5 (08-01) and when executing this code:

dl("php_mapscript.so");

$map = ms_newMapObj("../buses.map");

$imag = $map->prepareImage();

$l_stgo=$map->getLayerByName("arcosbase");
$l_stgo->set("status",1);

$l_stgo->draw($imag);

$bar = $map->drawScalebar();
$url_bar = $bar->saveWebImage(MS_PNG,0,0,0);
$map->drawLabelCache($imag);
$url = $imag->saveWebImage(MS_PNG, 0,0,0);

I get a:

Fatal error: Object has an invalid '_map_handle_' property in 
/var/www/html/ms_demo/php/layer.php on
line 11

If I change the $l_stgo->draw($imag); line to $imag=$map->draw(); 
it works perfectly.

Change History (5)

comment:1 by dmorissette, 23 years ago

See bug#23 for details on the original 'invalid _handle_' problems.

comment:2 by dmorissette, 23 years ago

   From:         "Doyon, Jean-Francois" <Jean-Francois.Doyon@CCRS.NRCan.gc.ca>
     To:         "'Daniel Morissette'" <morissette@dmsolutions.ca>

Dan,

Sorry, but look what I came upon :)

Fatal error: Object has an invalid '_map_handle_' property in
/home/ccatlas-prod/search/map.php3 on line 341

This is based on the following line of code:

$queryres = $reslay->querybypoint($querypoint,MS_SINGLE,-1);

This is a brand new PHP 4.0.6 and Mapserver from CVS from today ... (I just
migrated from PHP 3.0.17 and an old Mapserver, and am making the final
adjustments).

Any ideas?

Thanks,
J.F.

Here's the entire bit of code:

<...>
        } elseif ( $HTTP_POST_VARS["cmd"] == "query" ) {
                if ( $HTTP_POST_VARS["java"] == 1 ) {
                        $pixpoint =
split(",",$HTTP_POST_VARS["input_coord"]);
                } else {
                        $pixpoint[0] = $HTTP_POST_VARS["mapcoord_x"];
                        $pixpoint[1] = $HTTP_POST_VARS["mapcoord_y"];
                }
                $point = ms_newpointobj();
                $point->setXY($pixpoint[0],$pixpoint[1]);
                $extent = ms_newRectObj(); 
 
$extent->setextent($HTTP_POST_VARS["minx"],$HTTP_POST_VARS["miny"],$HTTP_POS
T_VARS["maxx"],$HTTP_POST_VARS["maxy"]);
                $map->zoompoint(1,$point,$map->width,$map->height,$extent);
                $newextent = $map->extent;
                $centerx = ($newextent->minx + (($newextent->maxx -
$newextent->minx)/2));
                $centery = ($newextent->miny + (($newextent->maxy -
$newextent->miny)/2));
                $querypoint = ms_newpointobj();
                $querypoint->setXY($centerx,$centery);
                $queryres = $reslay->querybypoint($querypoint,MS_SINGLE,-1);
<...>



comment:3 by dmorissette, 23 years ago

Status: newassigned
The following code will reproduce the problem in a PHP4.0.6 installation:

  $map = ms_newMapObj("/path/to/gmap75.map");
  $img = $map->prepareimage();
  $layer = $map->getLayerByName("bathymetry");
  $layer->set("status", 1);
  $layer->draw($img);

... we get this error:

Fatal error: Object has an invalid '_map_handle_' property in 
test_draw_map_invalid_handle.phtml on line 53

comment:4 by dmorissette, 23 years ago

Fixing _phpms_fetch_property_handle2() in php_mapscript_util.c to test for type 
IS_RESOURCE instead of IS_LONG makes the error go away for me and for 
Jean-Francois, but Vinko still gets the error... 

I'll need more info from him to try to reproduce the error he gets.

Note that JF gets new errors with this fix but I think they're unrelated.

comment:5 by dmorissette, 23 years ago

Resolution: fixed
Status: assignedclosed
Everything seemed to be working with the previous fixes except that reference 
counts were always too high and objects were never destroyed until the PHP 
cleanup.  Thanks to Zeev Suraski, one of the Zend developers, now I think I got 
this whole refcount thing right... reference counts seem to be exactly what they 
should be now.  Here are some details:

1- MAKE_STD_ZVAL() must be called to properly alloc and initialize a ZVAL before 
 creating a new object (except the 'return_value' passed by PHP4 which is 
already allocated and initialized)
2- This sets the initial ref count properly, even for objects embedded inside 
other objects.
3- Use add_property_zval() to add object properties in an object
4- In php_mapscript.c we used to fetch resource properties using 
phpms_fetch_property_long()... this called convert_to_long() internally which 
subtracted 1 to the reference count, and often caused early destruction of the 
associated resource object.  This explains some of the latest invalid 
_map_handle_ problems.  This has been fixed by adding a new 
phpms_fetch_property_resource function that does not affect the reference count.

Note that those fixes also fix the problem with shapefileObj->free() not closing 
the file properly (see bug#40).

Note: See TracTickets for help on using tickets.