"new" keyword/construction in UDTs

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
andrewwyld
New Member
New Member
Posts: 3
Joined: Mon Dec 08, 2008 7:08 pm

"new" keyword/construction in UDTs

Post by andrewwyld »

Hi there,

I am a bit new to PHP and CMS Made Simple, so this is perhaps a newbie question.  Appropriately enough, it concerns new and constructors.  My background is in C and C++ so it's quite likely I am making assumptions about how they work that are wrong.

I'm working on a UDT in CMS Made Simple 1.4.1 on PHP 5.1.6.  I have built a very simple XML file for use in a site; basically it contains contact details for various site offices, and each one has an ID which corresponds to a site id field in a SQL database.  I plan to grab the id, I use it to select the appropriate bit of the xml and I print the bits into a table.

Since the version of PHP I have is over five, I thought I would use the DOM, and found a nice (so I suppose) tute here:

http://devzone.zend.com/node/view/id/1713#Heading8

It suggests loading your XML using

$dom = new DomDocument();
$dom->load("articles.xml");

I have stuck something very similar into my UDT (identical barring variable and file names, basically) and I have discovered that it stops working around the point of the first statement (the construction statement).  Moving it up the file kills everything after it, and that goes with everything commented out but the construction statement, so it's definitely the actual construction that is causing the grief.  It seems to parse fine.  I also found that the class is actually DOMDocument so I changed the capitalization; no effect.

Anyway, I had had problems with global variables earlier (I had to specify they were global within the UDT, which I didn't think you had to do if you declared them outside a function) so I wondered if UDTs mess around with memory management in some way?  Alternatively, do I have to tell the UDT to use the DOM in a sort of #include kind of a way?  Is it something compeltely different?

Thanks!
Last edited by andrewwyld on Mon Dec 08, 2008 7:26 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: "new" keyword/construction in UDTs

Post by calguy1000 »

Nope, UDT's are essentially PHP functions that are stored in the database.  The problem with globals that you had was not UDT related, it's a PHP inexperience thing.

If you're experiencing problems like this check your error log.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
andrewwyld
New Member
New Member
Posts: 3
Joined: Mon Dec 08, 2008 7:08 pm

Re: "new" keyword/construction in UDTs

Post by andrewwyld »

Re globals, that was what I thought it might be—from what I read variables act global if you declare them at global scope, so if you declare them at function scope (like in a UDT) you'd need to specify they were global.  I am slightly surprised it let me define a function in the UDT if the UDT was itself a function, but I am not complaining :)

I have no access to the log, unfortunately.  What logs I can find are yesterday's.  However, I did try

if(class_exists("DOMDocument")){
  print "CHING CHING!";
}
else{
  print "no beans for you";
}

and there were no beans for me.  Is there any reason why DOMDocument would be missing, or why class_exists("...") might return a false negative?
Last edited by andrewwyld on Mon Dec 08, 2008 10:25 pm, edited 1 time in total.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: "new" keyword/construction in UDTs

Post by calguy1000 »

that'd be a PHP config issue.....

do a phpinfo(); see what is returned

the DOM stuff should be in there somewhere.
if it isn't (and I'll bet it isn't)... contact your host.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
andrewwyld
New Member
New Member
Posts: 3
Joined: Mon Dec 08, 2008 7:08 pm

Re: "new" keyword/construction in UDTs

Post by andrewwyld »

Aha!  It was apparently built with --disable-dom.  God knows why.  Thanks!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: "new" keyword/construction in UDTs

Post by calguy1000 »

and btw... php allows for nested functions.

Code: Select all

<?php
function pythag($a,$b)
{
  function square($n)
  {
     return $n * $n;
  }

  return sqrt(square($a)+square($b));
}

echo "pythag of 5 and 4 is ".pythag(5,4)."<br/>";
?>
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “Developers Discussion”