Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13

Thread: 2 PhP Questions

  1. #1
    Regular Coder
    Join Date
    Feb 2010
    Posts
    208
    Thanks
    15
    Thanked 2 Times in 2 Posts

    2 PhP Questions

    1. What means this line? Why we use -> in PHP??
    PHP Code:
    $this->cookie_data    = array('u' => 0'k' => ''); 
    2. Can I execute the function which I created like:

    PHP Code:
    function talk() {
    echo 
    "word";

    .. by entering url like: talk.php?talk ??

    Thanks in advance

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    the -> operator refers to a method or property of the class.

    so if you have a class with the following properties:

    name
    address

    you could access and modify them like this:

    class->name = "myName";

    echo class->name; //will print "myName"

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Regular Coder
    Join Date
    Feb 2010
    Posts
    208
    Thanks
    15
    Thanked 2 Times in 2 Posts
    thanks for first answer

  • #4
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    Question 2:

    Yes, like this:

    file.php?action=something

    file.php:
    PHP Code:
    if($_GET['action'] == 'something') {
        
    talk();
    }

    function 
    talk() {
        echo 
    'word';

    The "action" parameter can be named whatever you want. You access it using the $_GET superglobal.

  • #5
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Another way of doing it is this.

    PHP Code:
    if (isset($_GET["x"])) {
        
    $x explode(":",$_GET["x"]);

        switch(
    $x[0])
        {
            case 
    'talk':
                
    talk();
            break;

     }
    }

    function 
    talk() {
    echo 
    'Hello';

    That will give you this talk.php?x=talk
    rename the X's to whatever word you want it to be.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #6
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    Why the explode on the GET parameter?

  • #7
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Because if you had say a userid. You could do

    talk.php?x=talk:71
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    But then why not just another GET so like talk.php?x=talk&id=71
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #9
    Regular Coder
    Join Date
    Feb 2010
    Posts
    208
    Thanks
    15
    Thanked 2 Times in 2 Posts
    nice ways to use this... thx again guys.

  • #10
    Regular Coder
    Join Date
    Feb 2010
    Posts
    208
    Thanks
    15
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by whizard View Post
    the -> operator refers to a method or property of the class.

    so if you have a class with the following properties:

    name
    address

    you could access and modify them like this:

    class->name = "myName";

    echo class->name; //will print "myName"

    Dan

    What do you mean class?? Can you give me a working examle of this class->name using?? I will be thankful

  • #11
    Regular Coder
    Join Date
    Jan 2009
    Posts
    193
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Quote Originally Posted by auriaks View Post
    What do you mean class?? Can you give me a working examle of this class->name using?? I will be thankful
    Take a look at http://php.net/manual/en/language.oop5.basic.php

  • #12
    Regular Coder
    Join Date
    Feb 2010
    Posts
    208
    Thanks
    15
    Thanked 2 Times in 2 Posts
    it is needed to use public functions?? why not just functions?

  • #13
    Regular Coder
    Join Date
    Jan 2009
    Posts
    193
    Thanks
    0
    Thanked 20 Times in 20 Posts
    Quote Originally Posted by auriaks View Post
    it is needed to use public functions?? why not just functions?
    Try googling object oriented programming (OOP) and read up on it. It is kind of hard to explain in a post. Try reading this one http://www.devarticles.com/c/a/PHP/O...amming-in-PHP/


  •  

    Posting Permissions

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