[Mapserver-users] Looseing reference to classes when ms_newClassObj is run

Benjamin Wragg bwragg at tpg.com.au
Thu Jan 8 16:59:20 EST 2004


This is a multi-part message in MIME format.

------=_NextPart_000_0001_01C3D68A.ADF82EA0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hi all,
 
I'm currently writing some PHP classes to wrap some functions around the
Mapscript classes like the layer, class and map classes. I've run into
some trouble with references to objects and it seems that the
ms_newClassObj function is whats messing things up. I know that sounds
strange but let me try and explain.
 
I have made my own php LayerObj object which has a msLayer property
($layer->msLayer) which holds a layer object that is returned from
running ms_newLayerObj. So I create a new LayerObj and I get a
ms_newLayerObj created as a property of my object. eg.
 
    $layer = new LayerObj($map);
    //I now can access the ms layer object through
    $layer->msLayer->('name','Test layer');
 
    class LayerObj{
        var $msLayer;
 
        function LayerObj(&$mapObj){
            $this->msLayer=ms_newLayerObj($mapObj);
        }
        ...other methods
    }
 
I've written some functions in my LayerObj which act as a wrapper to the
mapserver layer functions. e.g set connection type, etc. These all work
well. When I compare the properties of $layer->msLayer to the properties
of $map->getLayer(x) I can see they are both pointing to the some object
in memory. I've got Zend studio and I can change a property of
$layer->msLayer and I see the changes reflected in the $map->getLayer(x)
instantly.
 
All the code works well until I get too the line where I add a Class to
the layer:
 
    $class=ms_newClassObj($layer->msLayer);
    
If at this point I check the numclass property I get two different
results:
 
    $layer->msLayer->numclasses;
    //Prints 1
 
    $map->getlayer(x)->numclasses
    //Prints 0
 
It seems as soon as I run ms_newClassObj the reference between the
mapserver layer and the mapserver map object gets severed! Any ideas?
 
Thanks,
 
Benjamin Wragg
 

------=_NextPart_000_0001_01C3D68A.ADF82EA0
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<TITLE>Message</TITLE>

<META content=3D"MSHTML 6.00.2800.1276" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D312220721-08012004>Hi=20
all,</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D312220721-08012004>I'm =
currently=20
writing some PHP classes to wrap some functions around the Mapscript =
classes=20
like the layer, class and map classes. I've run into some trouble with=20
references to objects and it seems that the ms_newClassObj function is =
whats=20
messing things up. I know that sounds strange but let me try and=20
explain.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D312220721-08012004>I have =
made&nbsp;my=20
own php&nbsp;LayerObj object which has a msLayer property=20
($layer-&gt;msLayer)&nbsp;which holds a layer object that is returned =
from=20
running ms_newLayerObj. So I create a new LayerObj and I get a =
ms_newLayerObj=20
created as a property of my object. eg.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;=20
$layer =3D new LayerObj($map);</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;=20
//I now can access the ms layer object through</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;=20
$layer-&gt;msLayer-&gt;('name','Test layer');</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;=20
class LayerObj{</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
var=20
$msLayer;</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
function=20
LayerObj(&amp;$mapObj){</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;=20
$this-&gt;msLayer=3Dms_newLayerObj($mapObj);</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
}</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
...other=20
methods</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D312220721-08012004>I've =
written some=20
functions in my LayerObj which act as a wrapper to the mapserver layer=20
functions. e.g set connection type, etc. These all work well. When I =
compare the=20
properties of $layer-&gt;msLayer to the properties =
of&nbsp;$map-&gt;getLayer(x)=20
I can see they are both pointing to the some object in memory. I've got =
Zend=20
studio and I can change a property of $layer-&gt;msLayer and I see the =
changes=20
reflected in the $map-&gt;getLayer(x) instantly.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D312220721-08012004>All =
the code works=20
well until I get too the line where I add a Class to the=20
layer:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;=20
$class=3Dms_newClassObj($layer-&gt;msLayer);</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;=20
</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D312220721-08012004>If at =
this point=20
I&nbsp;check the numclass property I get two different=20
results:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;=20
$layer-&gt;msLayer-&gt;numclasses;</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;=20
//Prints 1</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;=20
$map-&gt;getlayer(x)-&gt;numclasses</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D312220721-08012004>&nbsp;&nbsp;&nbsp;=20
//Prints 0</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D312220721-08012004>It =
seems as soon as=20
I run ms_newClassObj the reference between the mapserver layer and the =
mapserver=20
map object gets severed! </SPAN></FONT><FONT face=3DArial size=3D2><SPAN =

class=3D312220721-08012004>Any ideas?</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004>Thanks,</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D312220721-08012004>Benjamin=20
Wragg</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D312220721-08012004></SPAN></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0001_01C3D68A.ADF82EA0--




More information about the mapserver-users mailing list