SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 26

Thread: Class Basic ??

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Class Basic ??

    PHP Code:
    <?php
    class Details
    {
    var 
    $property1;
    var 
    $property2;

    function 
    display($name$age)
    {
    print 
    "Your name is : $name<br>";
    print 
    "Your age is: $age<br>";
    }
    }

    $obj = &new Details;
    $obj->name 'Jamie';
    $obj->age '13';
    $obj->display($obj->name$obj->age);

    ?>
    Is This Right
    Last edited by AnthonySterling; Apr 6, 2011 at 13:42. Reason: added [php] tags

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Hi Jamie, welcome to SitePoint!

    Well, that would depend on what you're planning on doing.

    How does this look?

    PHP Code:
    <?php
    class User
    {
      public 
    $forename;
      public 
    $surname;
    }

    class 
    UserPrinter
    {
      public static function 
    display(User $user){
        echo 
    'Hello '$user->forename', your surname is '$user->surname;
      }
    }

    $me = new User;
    $me->forename 'Anthony';
    $me->surname 'Sterling';

    UserPrinter::display($me);

    /*
      Hello Anthony, your surname is Sterling
    */
    What material are you using, have you tried the manual ? If you're struggling with PHP's OOP features, maybe you should start a little lower down and work your way up.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,087
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    A more usual setup is something like this:

    PHP Code:
    <?php
    class Details
    {
      private 
    $name;
      private 
    $age;

      public function 
    __construct($name$age)
      {
         
    $this->name=$name;
         
    $this->age=$age;
      }
     
      function 
    display()
      {
        print 
    "Your name is : $this->name<br>";
        print 
    "Your age is: $this->age<br>";
      }
    }

    $obj = new Details('Jamie'13);
    $obj->display();
    ?>
    Last edited by AnthonySterling; Apr 6, 2011 at 13:44. Reason: Slight correction, sorry Scallio! :)
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and how would i make this work with using gphpedit

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh ok thanks.

  6. #6
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where would i find any php applications to run it

  7. #7
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    What operating system are you using Jamie? If you're using a Windows machine, you can install 'wampserver', this will install a full web server for you.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  8. #8
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Lorna Jane Mitchell recently posted a presentation on Basic PHP OOP over at SlideShare, hopefully they can help you too.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  9. #9
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im using linux mint 10

  10. #10
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Hi Jamie,

    I see you're using gphpedit, which is a *nix app I believe. If you're using Linux Mint or Ubuntu, you will need to install PHP first.

    To get php to run in the Terminal, you will need to issue the following commands - in order:-

    Code:
    sudo apt-get update
    Code:
    sudo apt-get install php5-cli
    Once this is complete, you can run a PHP script like so...

    Code:
    sudo clear && sudo php -f path/to/php/file.php
    For example, if your php script was saved in your Documents folder as script.php, you would execute...

    Code:
    sudo clear && sudo php -f ~/Documents/script.php
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  11. #11
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ive already done php5 and thanks for the help

  12. #12
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    So, is it working?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  13. #13
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    its saying invalid operation - - "f"

  14. #14
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Save a script called script.php in your Documents folder, and in that script put the following...
    PHP Code:
    <?php
    echo 'Hello Jamie, today is 'date('l'), '.';
    Then (copy/paste ?), execute the following command in the terminal...
    Code:
    sudo clear && sudo php -f ~/Documents/script.php
    You should get...
    Code:
    Hello Jamie, today is Wednesday.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  15. #15
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by JamieHxD View Post
    its saying invalid operation - - "f"
    sudo: invalid option -- 'f'
    usage: sudo -h | -K | -k | -L | -V
    usage: sudo -v [-AknS] [-p prompt]
    usage: sudo -l[l] [-AknS] [-g groupname|#gid] [-p prompt] [-U username] [-u
    username|#uid] [-g groupname|#gid] [command]
    usage: sudo [-AbEHknPS] [-C fd] [-g groupname|#gid] [-p prompt] [-u
    username|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] [<command>]
    usage: sudo -e [-AknS] [-C fd] [-g groupname|#gid] [-p prompt] [-u
    username|#uid] file ...

  16. #16
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not open input file

  17. #17
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Are you sure you're copying the command I posted above exactly?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  18. #18
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Ok, where did you save the file? Are you following these steps ?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  19. #19
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok im following the exact steps and i've saved it in documents and its still saying no input file

  20. #20
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok doesnt matter im thinking it automatically saves it as php ok ive got it to work now

  21. #21
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Okay.

    Start a new terminal session, in that type

    Code:
    cd ~/Documents
    Then execute

    Code:
    ls
    What is displayed?
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  22. #22
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Brilliant! Good work!

    Now you know the command to execute that script, feel free to change it and play about.

    I'm glad you go it working Jamie, you know where we (SitePoint, ScallioXTX and I) are if you need any more help.

    Anthony.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  23. #23
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i've tried to get time and this come up XD


    <?php
    echo 'Hello Jamie, today is ', date('l'), '.', time ('l'),'.';

  24. #24
    SitePoint Enthusiast
    Join Date
    Apr 2011
    Location
    north-east england
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok this is shown c.vvvv.odt Jamie PhP script.php

  25. #25
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Use gedit to save the file in the Documents folder as script.php.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


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
  •