You are here: php 4 Classess "__get" use clarification. Only 1 "__get" per class? « PHP Language « IT news, forums, messages
php 4 Classess "__get" use clarification. Only 1 "__get" per class?

Posted by cluthz on 05/07/07 15:06

Hi there,

I'm going to create a class in one of my PHP4 applications for the first
time. However I was reading up about the
__get and __set functions within a class.

Reading about OO / classes I would expect to be able to create a get
function for each public variable.

Therefore if I has class example:

class example {

var $test1;
var $test2;

}

I would expect to be able to add the functions (something like the
following)
__get ($test1) {
#Do stuff with test1
return $this->$test1;
}

__get ($test2) {
#Do stuff with test2
return $this->$test2;
}

But reading about it, it seems that I can only have a single __get function
per class and that within the __get function I have to test for which
variable is being set.

e.g.
__get ($name) {

switch ($name) {
case "test1":
#Do stuff with test1
return $this->$test1;
case "test2":
#Do stuff with test2
return $this->$test3;
case default:
echo "error";
}
}

This is not what I would expect of OO behaviour from what I have read
elsewhere.

Can someone please help me to confirm to me how this works.

Thanks in advance.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация