CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Basic Object

  1. #1
    Join Date
    May 2006
    Posts
    306

    Basic Object

    Okay so how would this be accomplished in PHP? I want to make a simple object.
    Code:
    //JS
    var Obj = new Object();

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    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.

  3. #3
    Join Date
    May 2006
    Posts
    306

    Re: Basic Object

    Oh I thought there was something like $stdobj.

    I know about the JS, same with arrays. use ( = [] ) instead of ( = new Array(); )

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Basic Object

    Quote Originally Posted by code? View Post
    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; 
    Quote Originally Posted by code? View Post
    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.

  5. #5
    Join Date
    May 2006
    Posts
    306

    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
  •  





Click Here to Expand Forum to Full Width

Featured