04-18-2009, 07:43 AM
|
#4 (permalink)
|
|
The Frequenter
Join Date: Sep 2007
Location: Denmark
Posts: 352
Thanks: 8
|
Quote:
Originally Posted by allworknoplay
Salathe/Tanax & company:
I currently have a method that needs to return 2 variables...maybe even 3, but let's say 2 for now. I'm currently doing it this way, do you know of any better way of doing it?
Tanax, this might look familiar to you....
Code:
function viewPage() {
//DO SOMETHING HERE AND RETURN DATA
$viewPageEntry[] = $this->starting_no;
$viewPageEntry[] = $this->end_count;
return $viewPageEntry;
}
In my HTML I am calling it and then assigning it to a variable,
then accessing each data this way.
Code:
$getViewPage = $pagination->viewPage();
echo $getViewPage[0];
echo $getViewPage[1];
I thought maybe OO was a bit more powerful or had a better way to access its data?
I thought maybe I would be able to access the data this way but it doesn't work.
Code:
echo $pagination->viewPage(starting_no);
echo $pagination->viewPage(end_count);
Maybe I should access it statically? Would that work?
Code:
$getViewPage::starting_no
$getViewPage::end_count
I get this error when I try the above code:
|
Paamayim Nekudotayim means "Double colon" in hebrew.
You cannot call a property like that in versions prior to PHP 5.3, in 5.3 and newer it will call the constants named 'starting_no' and 'end_count'. To call a property staticlly you need to call it with a class name:
PHP Code:
echo ClassName::$property;
The following will call a constant:
PHP Code:
echo ClassName::CONSTANT;
or inside a class you can use self:: and parent:: instead of the class name if you are within a method scope of the class.
In PHP 5.3 the following is possible:
PHP Code:
class A
{
public static $b;
public function __construct()
{
/* Sets A::$b staticlly */
$this::$b = 'ABC';
}
}
$a = new A;
echo '$a::$b: ' . $a::$b . PHP_EOL;
echo 'A::$b: ' . A::$b . PHP_EOL;
It will print:
Code:
$a::$b: ABC
A::$b: ABC
Because the dynamic syntax is possible here ;)
__________________
|
|
|