You are here: Re: SOAP question - creating instances/ accessing constructor method? « PHP Programming Language « IT news, forums, messages
Re: SOAP question - creating instances/ accessing constructor method?

Posted by Janwillem Borleffs on 10/30/53 11:25

Piro wrote:
> Also, I noticed you wrote a method to return a class property... is
> there any way to access the property directly? Rather than
>
> print $client->getName();
>
> I was thinking
>
> print $client->name;
>
> It seems cumbersome to have methods for each class property, especially
> if there are a bunch of them.
>

Perhaps, but in general it's considered bad practise to access class
properly without a getter, unless they are defined as public statics.

Anyways, when you don't want to define setters, you can use overloading
by adding the following method to your class:

public function __call($function, $arguments) {
$function = strtolower($function);
$var = preg_replace('/^get/', '', $function);
if (isset($this->$var)) {
return $this->$var;
}
}

This way you can use method calls like $client->getName() to get a
property with the name $name, $client->getAnother_name() to get a
property with the name $another_name etcetera.

And, as you have might have guessed by now, there isn't a way to access
teh class properties directly as setClass() only exports class methods.


JW

 

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

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