04-18-2009, 12:48 PM
|
#5 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
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:
|
Yah, remember that the code I used for that pagination class I wrote is quite old. Anyhow, to the function, I just returned an array because I felt it would be easier.
You however, could create 2 functions for it.
PHP Code:
$starting_no = $pagination->getStart();
$end_cound = $pagination->getEnd();
Surely you can do them staticly, but remember you need to set the class variables to public then - which I strongly advice you not to do, 'cause then you can also accidently change the value aswell Classname::$variable = "bogus" which, needless to say, is quite a security issue.
It's safer to have a method instead to fetch a private classvariable, that way you can be sure that it's only able to return the current value, and never change it.
__________________
|
|
|
|