|
-
November 23rd, 2008, 07:59 PM
#1
Basic Object
Okay so how would this be accomplished in PHP? I want to make a simple object.
Code:
//JS
var Obj = new Object();
-
November 24th, 2008, 10:39 AM
#2
Re: Basic Object
You would use classes in PHP. This is where it gains the title as an object-oriented language.
Also, in JavaScript, you should use string literals rather than the whole object. This allows you for creation of the member's methods and functions at the implementation of the actual object's definition.
Code:
var theObject = {};
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
November 25th, 2008, 05:18 AM
#3
Re: Basic Object
Oh I thought there was something like $stdobj.
I know about the JS, same with arrays. use ( = [] ) instead of ( = new Array(); )
-
November 25th, 2008, 08:37 AM
#4
Re: Basic Object
 Originally Posted by code?
Oh I thought there was something like $stdobj.
There is. One of the basic variable types is object. Here's a little example.
PHP Code:
class testClass { public $testVariable = 'Test method complete.';
function testMethod() { echo $this->testVariable; // class methods can access shared variables } }
$testObject = new testClass(); $testObject->testMethod(); // outputs Test method Complete;
 Originally Posted by code?
I know about the JS, same with arrays. use ( = [] ) instead of ( = new Array(); )
Yes, literals can be used with arrays [] as well as objects {}.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
November 25th, 2008, 01:35 PM
#5
Re: Basic Object
Oh ok, thanks, that helped.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|