I've just got a couple questions to get out.
The first deals with OOP. I'm by no means new to PHP, but this is my first time dealing with OOP. For the most part, I think I'm doing alright with it so far. But I'm a bit confused with how to deal with arrays.
Say you have a class, functions, that takes templates from a database and caches each individual template as part of the array $templates. So, like this:
<?
class functions {
var $templates;
function templates() {
//query templates...etc.
$template[body] = $template_from_database;
$template[header] = $template_from_database;
$template[footer] = $template_from_database;
$this->templates = $template;
}
}
$page = new functions;
$page->templates();
?>
Just an example, but you get the idea. Now having executed that script, you can then refer to the array parts as $page->templates[body], $page->templates[header] and so forth. But sometimes, I like to do more with my arrays. For instance, say I wanted to pass the $page->templates through a foreach() statement, and then print the title and value for each page.
foreach($page->templates AS $element->$value) {
echo "$element | $value";
}
(note: thinking it could just be a problem of referring directly to a class in the statement, I also tried defining a new array with the value of $page->templates and putting that array through the statement: Same result)
But upon trying this, the first thing I noticed is that...well...it doesn't work.:p Actually, I tried just printing th $element value, and it just printed "Object." So obviously, though I can refer to this array like any normal array, the array is somehow behaving differently. So would someone like to either enlighten me on how to make it behave like a normal array, or point out something stupid that I'm probably doing?
Second question isn't so much of a coding problem..well, it is and it isn't. I've built a quick little script that allows me to write and update my php pages through my browser (poor practice, I know, but it has its uses), which is accomplished by storing the php code in a MySQL database and evaluating it as php code. I'm doing this all on my own personal server - when you're using a 56k modem that acts like a 28k, it speeds up the development process immensely if you don't have to constantly upload files if you can help it(besides, it's kind of a pain in the ass). Now I don't have the patience, desire, nor technical know-how to setup my own Apache webserver on a Linux system, so I've setup php, mysql and a Badblue server on my WinXP system. It serves my purposes. I ran this setup for around a year on a Windows 98 system, and never had any problems. But when it came to building a login script, this setup starting giving me problems.
I like to use sessions, and so I started building a login script using the most basic form of sessions you can have: Just using session_start(); and then defining $_SESSION variables. I can deal with the details of the script later. Anyway, the page had a heart attack when I tried calling session_start(), saying that the drive "/tmp" hadn't been set. No big deal, just change it to a valid directory, right? So I made a php.ini file setting the session folder to /windows/temp. Great, no more error... until I went through my script to edit the page source. I insert my php coding through mysql via the old addslashes method (I'm not too trusting of magic_quotes). For part of this, it included adding the code
eval("\$page_source = \"$template[index.php]\";");
I never had a problem editing or inserting this information to the database before. I always managed to get the info stored and retrieved in exactly the format I wanted it in. But after implementing sessions, it for some reason removed all of my slashes from these eval() statements when I went to insert the code to the database, and so all new errors started popping up.
Thinking it might just be some other setting in the (recommended) php.ini file I was using, I removed it and my sessions, put the original code back into the database, and tried loading the page again. Problem solved, so it had to be something with my php.ini. Great, but I still want sessions.
So since I was a bit too lazy to search through the whole ini file to see what might be causing php to act this way, I thought I'd take the lazy approach. That is, adding this to my header:
ini_set("session.save_path", "/windows/temp");
Great, so my sessions were back up and running.
...until that same problem with my slashes returned. So for some reason, changing my session.save_path has the added effect of altering the way I send data the database? How the hell does THAT work? 0_O