...

View Full Version : 2 PhP Questions



auriaks
03-14-2010, 09:37 PM
1. What means this line? Why we use -> in PHP??

$this->cookie_data = array('u' => 0, 'k' => '');

2. Can I execute the function which I created like:


function talk() {
echo "word";
}

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

Thanks in advance :)

whizard
03-14-2010, 10:33 PM
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

auriaks
03-14-2010, 10:50 PM
thanks for first answer :)

bacterozoid
03-15-2010, 02:18 AM
Question 2:

Yes, like this:

file.php?action=something

file.php:


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.

masterofollies
03-15-2010, 02:35 AM
Another way of doing it is this.


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.

bacterozoid
03-15-2010, 02:52 AM
Why the explode on the GET parameter?

masterofollies
03-15-2010, 03:53 AM
Because if you had say a userid. You could do

talk.php?x=talk:71

_Aerospace_Eng_
03-15-2010, 04:44 AM
But then why not just another GET so like talk.php?x=talk&id=71

auriaks
03-15-2010, 04:42 PM
:) nice ways to use this... thx again guys.

auriaks
03-15-2010, 04:43 PM
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 :)

skywalker2208
03-15-2010, 04:46 PM
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

auriaks
03-15-2010, 05:07 PM
it is needed to use public functions?? why not just functions?

skywalker2208
03-15-2010, 05:28 PM
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/Object-Oriented-Programming-in-PHP/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum