SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict bkennedy's Avatar
    Join Date
    Aug 2004
    Location
    michigan
    Posts
    251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    assigning class variable at declaration

    I have a question, regarding PHP4.
    (I only have 5 right now)

    can I assign a variable in a class by calling a method of the class? like so:
    PHP Code:
    class bob{
        var 
    $name=$this->getname();

        function 
    getname(){
            return 
    "bob";
        }

    or will that give me an error?
    ----------------
    bob.kennedy
    ----------------

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    see Where should I post my thread?

    For your question:

    PHP Code:
    class bob{
        var 
    $name;
        function 
    bob() {
            
    $this->name $this->getName();
        }
    // the rest including getName()

    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •