[MS4W-Users] Missing functions/attributes in MapScript (PHP)
Gramenz, Jens
Jens.Gramenz at leibniz-liag.de
Mon Jan 31 16:35:10 UTC 2022
Dear Jeff,
thank you for the quick and helpful answer. You were right, I didn't RTFM... :-) At least I didn't do it carefully enough. Sorry for that.
I obviously must have looked at getMetaData() at mapObj level, since I was sure I checked if there was a deprecation note. On layerObj level (where the error happened) there is one indeed. With get() instead of direct access I could make it working again. To be honest I didn't even realise, that the hashTableObj is not a built-in type, but a mapscript one. Ouf!
Regarding the wiki: I'm not sure if I can really contribute to that. Other than the getMetaData() stuff, I think I only ran into layer level issues regarding color and opacity, which all three are already explicitly mentioned. Maybe the "new" case-sensitivity is a point?! The non-existence of mapObj->numLayers I moaned about last time, just wasn't working due to case-sensitivity. o_O Don't know how that made its way into the project... :-D
Normally I wouldn't even dare mentioning it, but since it worked in the past, others might also step into that?! I don't know if that is just a PHP thing, but I guess those things only happen in PHP. Still like it though. ;-)
Thanks again,
Jens
-----Ursprüngliche Nachricht-----
Von: MS4W-Users <ms4w-users-bounces at lists.ms4w.com> Im Auftrag von Jeff McKenna via MS4W-Users
Gesendet: Freitag, 28. Januar 2022 19:56
An: ms4w-users at lists.ms4w.com
Cc: Jeff McKenna <jmckenna at gatewaygeomatics.com>
Betreff: Re: [MS4W-Users] Missing functions/attributes in MapScript (PHP)
ACHTUNG!! Diese E-Mail erreicht Sie von einem Absender außerhalb der GZH-Infrastruktur. Bitte klicken Sie auf keine Links oder öffnen Sie keine E-Mail-Anhänge, falls Sie den Absender nicht kennen und nicht wissen, ob der Inhalt sicher ist.
Hi Jens,
Thank-you for the complements.
In the MS4W 5.0-beta2 announcement I mentioned that I had created a Migration Guide on the wiki, that I recommend that you take the time to go through in detail: https://ms4w.com/trac/wiki/MigrationGuide5.x
There you will find a section on SWIG MapScript, that also includes 4 working PHP scripts for MS4W 5.0-beta2, with a note about changes to setting metadata using the new hashTableObj way. I also now added a working example for *getting* a metadata value (see the last 'echo'
command below), such as:
<?php
//set metadata using the new 'metadata' hashTableObj keys and value directly
$oWMSLayer->metadata->set("wms_name", "popplace");
$oWMSLayer->metadata->set("wms_title", "Cities");
$oWMSLayer->metadata->set("wms_srs", "EPSG:3978");
$oWMSLayer->metadata->set("wms_server_version", "1.1.1");
$oWMSLayer->metadata->set("wms_format", "image/png");
//get metadata using the new 'metadata' hashTableObj keys directly
echo $oWMSLayer->metadata->get("wms_title");
?>
As always, I kindly ask you that you add to that wiki page, by adding your examples and notes so others can learn from your tips. (it's a wiki on purpose, to hopefully get everyone editing it and adding migration examples, as you modify your mapfiles for MS4W 5.0).
I hope this brings you out of the 'darkness', ha, and that you have a nice, quiet weekend.
Thank-you for using MS4W.
"MS4W: open doors as well as windows"
-jeff
--
Jeff McKenna
GatewayGeo: Developers of MS4W, MapServer Consulting and Training co-founder of FOSS4G http://gatewaygeo.com/
On 2022-01-28 6:48 a.m., Gramenz, Jens via MS4W-Users wrote:
> Dear list and especially dear Jeff,
>
> thank you for creating and supporting MS4W. Although MS4W doesn't
> completely fit our demand, it is marvelous how easy it is to set it
> up. :)
>
> I wanted to have a look at the new Mapserver/PHP-Combo and tried to
> make one of our projects work with it. After fixing some deprecations
> here and there, I encountered some difficulties with MapScript I was
> not able to circumvent. :(
>
> When switching to PHP7 I had to include the php_mapscript.dll and (I
> guess that was the SWIG-Version then?!) a mapscript.php.
>
> Sven brought this up in a message in december. This time there is no
> more mapscript.php and if I include the old one it raises an error,
> that the classes are already there, which is plausible. But if I don't
> it seems that there is something (i.e. some functions and attributes [e.g.
> mapObject->numLayers]) missing. But in general MapScript is loaded and
> does work.
>
> Since I wasn't sure if it is a problem with my software setup, I used
> a plain version of MS4W (5beta2) on another machine to reproduce it.
> Took about 5 Minutes to unzip and about 5 seconds to make it work... Wow!
>
> An example to reproduce my problem is to add the following lines to
> quickmap.php at line 20 and comment the rest of the file.
>
> $layer = $oMap->getLayer(0);
>
> echo "Layer: ".$layer->name."<br>";
>
> print_r(get_object_vars($layer->metadata));
>
> echo $layer->metadata->wms_title."<br>";
>
> $layer->getMetaData("wms_title");
>
> Getting the layer and printing the name ("ocean") does work. The
> metadata actually is a hashTableObj, but get_object_vars gives an
> empty array. Directly accessing the attribute just returns NULL.
> Calling
> getMetaData() like we used to leads to the "Fatal error: Uncaught Error:
> Call to undefined method layerObj::getMetaData()" although is it
> mentioned in both the SWIG and PHP MapScript API.
>
> Don't know if these a bugs or features. =) Could it be that there have
> been some changes in the code that are not yet documented? Maybe one
> of you can bring some light into the darkness?!
>
> Kind regards,
>
> Jens
>
>
> _______________________________________________
> MS4W-Users mailing list
> MS4W-Users at lists.ms4w.com
> https://lists.ms4w.com/mailman/listinfo/ms4w-users
_______________________________________________
MS4W-Users mailing list
MS4W-Users at lists.ms4w.com
https://lists.ms4w.com/mailman/listinfo/ms4w-users
More information about the MS4W-Users
mailing list