martin.kahil Posted November 18, 2007 Share Posted November 18, 2007 Hi again, now i need to create some objects for my calennder.. I mean that I have 3 values for every date (at least) in my database. And I want to import it to the page, so I want to refer to it like thisObj.dateObj.value1Obj.value2How do I create something like this? And can I create an array of these? Link to comment Share on other sites More sharing options...
Ingolme Posted November 18, 2007 Share Posted November 18, 2007 Just create an object like this:Obj=new Object();Obj.date = [current date];Obj.value1 = "something";Obj.value2 = "something else"; Link to comment Share on other sites More sharing options...
martin.kahil Posted November 19, 2007 Author Share Posted November 19, 2007 Does not work. Thats the code <html><body><?php$O=new Object();$O.d="e";echo $O.d;?></body></html> And that the error I get Parse error: syntax error, unexpected '=' in /data/members/free/tripod/uk/m/a/r/martinkahil/htdocs/test.php on line 5 Link to comment Share on other sites More sharing options...
Ingolme Posted November 19, 2007 Share Posted November 19, 2007 PHP's . is a concatenating operator. PHP doesn't use the . level system.The code I gave you was javascript, that's my mistake. Link to comment Share on other sites More sharing options...
martin.kahil Posted November 19, 2007 Author Share Posted November 19, 2007 So I can't use objects in PHP? Link to comment Share on other sites More sharing options...
Ingolme Posted November 19, 2007 Share Posted November 19, 2007 Not in my knowledge, I haven't investigated much in that. It might be possible but even if you did, it wouldn't look the way it does in other languages, because PHP doesn't have a . level system. Link to comment Share on other sites More sharing options...
martin.kahil Posted November 19, 2007 Author Share Posted November 19, 2007 OK, I'll check it. but what do you mean with "a . level system"?? Link to comment Share on other sites More sharing options...
Ingolme Posted November 19, 2007 Share Posted November 19, 2007 I mean that there are levels indicated with .s Like root.level1.level2, that uses the . to get into a level. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 19, 2007 Share Posted November 19, 2007 He's talking about dot notation for referencing class members. PHP doesn't use dot notation, the member reference operator in PHP is ->. If you want the same sort of functionality in PHP that you get with Javascript objects, then you can use an array for that. Everything in Javascript is an array structure anyway. If you want more then what Javascript allows, with more of a full object-oriented interface, then you can define a class for your object and set up the properties and methods for it. Check these links, depending on the version of PHP you're using:http://www.php.net/manual/en/language.oop.phphttp://www.php.net/manual/en/language.oop5.php Link to comment Share on other sites More sharing options...
Synook Posted November 20, 2007 Share Posted November 20, 2007 PHP has definitely got more OO support than JavaScript! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.