Like simplexml does?Alrighty, basically what I'm trying to do is take an XML file and translate it into a nested collection of objects.
Object Oriented Predicament
Moderator: General Moderators
Re: Object Oriented Predicament
Re: Object Oriented Predicament
Holy toleto I am an idiot haha. My only trouble is that the structure of the XML file will be changing in depth, so I'm guessing the only way to make sure every generation of objects is accounted for would be to create a php file from a php script?
This helped a lot, thanks man. I'll try to keep the stupid questions at bay so I don't waste your time anymore.
This helped a lot, thanks man. I'll try to keep the stupid questions at bay so I don't waste your time anymore.
Re: Object Oriented Predicament
You don't need code generation for simple traversal of an arbitrary tree. I reckon you haven't had a formal training in programming, right? If so, you might be interested in reading up on functions and recursion - both topics have a direct application to your current issue.Skidmark wrote:My only trouble is that the structure of the XML file will be changing in depth, so I'm guessing the only way to make sure every generation of objects is accounted for would be to create a php file from a php script?
Re: Object Oriented Predicament
Hey yeah man I just solved it actually. Yeah you guessed right, google is my teacher haha. Is recursion when you have a function call itself in its definition? If so, then yeah haha.
Anyway, this one should be easy. What is it called when you translate text into MySQL safe text and back? I'm trying to store methods of presentation for some of my objects (HTML) in a MySQL database, and I don't want anyone putting functional drop table commands or anything in it. I know I've touched the function to be used before, the name just escapes me. Sorry for the annoyance again :\
Thanks guys, you are a great help. I'm chuggin along with this website because of you all, and for that I thank you. After I get good at this stuff I want to contribute as much as possible, it's the least I could do.
Anyway, this one should be easy. What is it called when you translate text into MySQL safe text and back? I'm trying to store methods of presentation for some of my objects (HTML) in a MySQL database, and I don't want anyone putting functional drop table commands or anything in it. I know I've touched the function to be used before, the name just escapes me. Sorry for the annoyance again :\
Thanks guys, you are a great help. I'm chuggin along with this website because of you all, and for that I thank you. After I get good at this stuff I want to contribute as much as possible, it's the least I could do.
Re: Object Oriented Predicament
Exactly.Skidmark wrote:Is recursion when you have a function call itself in its definition? If so, then yeah haha.
It's called escaping. This is pretty general concept not limited to just SQL - many languages/protocols include some way to escape the parsing so that what looks like a part of the language wouldn't be considered as such.Skidmark wrote:What is it called when you translate text into MySQL safe text and back? [...] I know I've touched the function to be used before, the name just escapes me.
For mysql there's http://us2.php.net/mysql_real_escape_string function, for html - http://us2.php.net/htmlspecialchars, for regexps - http://us2.php.net/preg_quote just to name a few.
Re: Object Oriented Predicament
Ahahaha wow, that's embarrassing. Thanks, that helped out a lot.
Anyway, here is my next challenge. I am making an object oriented method of generating MySQL "WHERE field operation value combination clause", so I can just generate code like that by saying $clause->get or something. Here is an example of a MySQL clause if you aren't familiar already: "SELECT * FROM Users WHERE postcount<'30' AND (username='Skidmark' OR email='brick@wall.com')".
Basically here is my plan of attack:
Make an abstract base class "Clause" that simply says that the child classes must have a "get()" function.
Make a child class that is a container of "field operation value" objects and relates them based off OR or AND. I have this part down.
For the "field operation value" predicament, here is what I did. I made an abstract class known as "simple" (simple because it only has one value and only one field) that said that get() was abstract, again. Now I don't really know the laws of PHP class abstraction; the online manual didn't explicitly say that I couldn't attempt what I was doing. Anyway, I simply made two extensions of that class, aswell. One for numeric operations and one for string based ones. I was basically wondering if there are any existing examples of this very thing I am doing (object oriented MySQL commands); I hate reinventing the wheel :\. Thank you all so much, you guys own so hard.
Anyway, here is my next challenge. I am making an object oriented method of generating MySQL "WHERE field operation value combination clause", so I can just generate code like that by saying $clause->get or something. Here is an example of a MySQL clause if you aren't familiar already: "SELECT * FROM Users WHERE postcount<'30' AND (username='Skidmark' OR email='brick@wall.com')".
Basically here is my plan of attack:
Make an abstract base class "Clause" that simply says that the child classes must have a "get()" function.
Make a child class that is a container of "field operation value" objects and relates them based off OR or AND. I have this part down.
For the "field operation value" predicament, here is what I did. I made an abstract class known as "simple" (simple because it only has one value and only one field) that said that get() was abstract, again. Now I don't really know the laws of PHP class abstraction; the online manual didn't explicitly say that I couldn't attempt what I was doing. Anyway, I simply made two extensions of that class, aswell. One for numeric operations and one for string based ones. I was basically wondering if there are any existing examples of this very thing I am doing (object oriented MySQL commands); I hate reinventing the wheel :\. Thank you all so much, you guys own so hard.