schlitt.info - php, photography and private stuff ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :Author: Tobias Schlitt :Date: Wed, 19 Nov 2008 23:29:46 +0100 :Revision: 1 :Copyright: CC by-nc-sa ==================== "Virtual properties" ==================== :Description: Jeff Moore posted an article on procata.com about getters, setters and real properties. I fully agree with him. Especially the usage of interceptors (__get()/__set()/__isset()/__call()) makes your API a lot more readable and comfortable, while maintaining the purpose behind getters and setters: Checking the correctness of values assigned to a property and wrapping around retrieval mechanisms for a property. I personally call the way of maintaining value-correctness for properties through interceptors **virtual properties**, which fits quite nice I think. Jeff Moore posted an `article on procata.com`__ about getters, setters and real properties. I fully agree with him. Especially the usage of interceptors (`__get()/__set()/__isset()/__call()`__) makes your API a lot more readable and comfortable, while maintaining the purpose behind getters and setters: Checking the correctness of values assigned to a property and wrapping around retrieval mechanisms for a property. I personally call the way of maintaining value-correctness for properties through interceptors **virtual properties**, which fits quite nice I think. .. __: http://www.procata.com/blog/archives/2007/05/08/let-your-properties-be-properties/ .. __: http://de.php.net/manual/en/language.oop5.overloading.php In `eZ Components`__ we make heavy use of this methodology, especially with our option classes. This allows nice looking code like: .. __: http://ez.no/ezcomponents :: $dialog->options->text = "Test text"; While the $dialog object ensures that it's $options property holds nothing but instances of the option class. The latter one ensures, that its $text property has a correct value at any time. If this is violated anywhere, an exception is thrown. I think this is much more intuitive and comfortable than :: $dialog->getOptions()->setText( "Test text" ); If you are interessted in this topic, you should buy the **upcoming issue of the German "PHP Magazin"**, which will contain an article about these techniques and some more advanced. .. Local Variables: mode: rst fill-column: 79 End: vim: et syn=rst tw=79 Trackbacks ========== - phentermine diet pills on Tue, 05 Feb 2008 12:31:03 +0100 in phentermine diet pills Blog - comprar ciprofloxacin on Tue, 05 Feb 2008 12:35:21 +0100 in comprar ciprofloxacin Trackback Comments ======== - Soenke at Tue, 08 May 2007 22:16:52 +0200 Hi, while interceptors or not is imho more or less a religious question, I personally don't like them. The main reason is that my IDE (Eclipse/Zend) doesn't complete my code anymore and I have to lookup everything in the (anyhow great) documentation :) But maybe there's a way to fake it for code inspection IDEs ... - Toby at Tue, 08 May 2007 22:19:08 +0200 phpDocumentor supports documenting virtual properties since some time. If you enhance your documentation, there is a rare chance that Zend IDE can parse the docs and do the completion for you. ;) - Matthew Turland at Wed, 09 May 2007 01:47:23 +0200 I believe you misread the post you are referencing. The blog belongs to a fellow by the name of Jeff Moore and he wrote the original article. I made the first comment to it, which actually stated that I did not care for the approach he described and listing reasons why. Please update your post accordingly to properly attribute the original article. Thanks. - Toby at Wed, 09 May 2007 07:20:57 +0200 Damn, you are so right. Dunno where I got the name from. Thanks for the hint, I fixed it immediatelly. - Markus Wolff at Wed, 09 May 2007 12:46:21 +0200 I have to agree with Soenke - although it's possible to document virtual properties for use with phpDocumentor, code completion in IDEs is still a big issue. I have only tried this in Zend Studio, but the @var tag definitely doesn't work for code completion there. As the Eclipse-based PHPIDE project will undoubtedly inherit a lot of Zend Studio's parsing code, I doubt it will be any better in that regard. So while I agree that interceptors are a cool and convenient way to solve a lot of problems, virtual properties and methods can also decrease developer productivity when you're used to having thorough code completion. - Toby at Wed, 09 May 2007 18:52:43 +0200 I'm actually unconcerned by the ZDE problem, since I'm using VIM. ;) - Markus Wolff at Wed, 09 May 2007 22:00:57 +0200 Somehow I knew you were gonna say that :-D - Toby at Thu, 10 May 2007 00:29:57 +0200 Yes? Why? ;) But joke aside, I actually think virtual properties are a great way of managing the getter/setter dilemma in a very elegant way. Therefore, and because PHP documentation tools already support this way of API design, the major IDE vendors should adopt it and also provide completion features for it. Or am I wrong? - sf at Fri, 11 May 2007 13:28:50 +0200 It's depends. Sometimes better used first, sometimes second code. - Ahmad Al Jayousi at Tue, 23 Nov 2010 14:36:38 +0100 Ahmad Al Jayousi Philadelphia University Jordan http://www.philadelphia.edu.jo E-mail: aaljayousi@philadelphia.edu.jo - Anoffjeokesex at Wed, 07 Sep 2011 13:23:36 +0200 Justified making my earliest mail at schlitt.info, which seems to be a wonderful forum! - AmbiguousBlogger.com at Fri, 30 Mar 2012 19:35:04 +0200 Did you ever think Wow, this is really a useful blog entry? Now you can give something back to the author with very little effort. Flattr is a new mirco-payment platform to revenue good, free content on the web. - Concerned Blog at Thu, 05 Apr 2012 13:04:36 +0200 This is a well written article on this subject. I have been looking at starting a new business and this is valuable information to help me in my decision. Thank you. - Properties in agra at Thu, 31 May 2012 09:03:58 +0200 Nowadays, finding a high quality post is really difficult. I’d like also to thank my friend for giving me the URL of your blog. Hope you appreciate my short comment. - Ekilibrium at Wed, 30 Jan 2013 14:07:43 +0100 Ekilibrium va ofera o gama larga de Tratamente naturiste: produse naturiste, tratamente naturiste, remedii naturiste, detoxifiere. http://www.ekilibrium.ro Tratament, tratamente Produse naturiste Tratamente naturiste Remedii naturiste Detoxifiere Tratamente detoxifiere Produse naturiste, Tratamente naturiste, Remedii naturiste Produse naturiste, Tratamente naturiste Tratamente naturiste, Remedii naturiste Produse naturiste, Remedii naturiste - logintrans at Wed, 30 Jan 2013 14:08:00 +0100 Schimburi de informatii despre firmele de transport, expeditie, productie si comert. http://www.logintrans.ro Bursa de marfuri Marfa Bursa transport Transport Transport international Transport rutier Transport marfa Logistica Expeditie Casa expeditie - KND Digital at Wed, 30 Jan 2013 14:08:20 +0100 Our high qualified personnel take care about you and your business when it comes to web development for Brisbane market. We are providing to our clients web development services in order to attract viewers, to help them promoting their products or services. To succeed in offering web development to the customers in Brisbane, we use all our resources and all our skills http://www.knd.com.au web development Brisbane web design Brisbane Magento developer brisbane Brisbane web design Content marketing Brisbane Seo brisbane Ecommerce Brisbane Social marketing Brisbane - tagarrestreview.com at Sat, 16 Mar 2013 12:37:54 +0100 Great instructions! The setup procedure explained here are easy to follow even by a computer beginner. I think this one is more comfortable to find out the exact values than the previous one. Thank you for the instructions! - www.joylandfun.com at Thu, 25 Apr 2013 02:39:37 +0200 cool post. yes i like it very much thanks a lot .this blog have very deep information for a men - giftsguide at Thu, 25 Apr 2013 09:16:43 +0200 An anniversary gift is the opportunity to show your loved one precisely how much they mean to you and how special you think they are. - itassetmanagementhelp at Thu, 25 Apr 2013 09:16:57 +0200 Information technology allows health care organizations to have a better handle on their quality management efforts. Health care organizations can set up computer systems to perform automated quality assurance audits and generate reports on the findings - office2010professional at Thu, 25 Apr 2013 09:17:23 +0200 Obtain a business license. This is usually not difficult to do. In most jurisdictions, the business license for starting up a service related business such as IT support requires filling out a few forms and paying a fee. - buymotorbike at Thu, 25 Apr 2013 09:17:42 +0200 Yamaha motorbikes are a great option if you are looking to purchase your first motorbike. With the help of a Yamaha motor bike dealer, you will be well on your way to living your dream. - onlinedatastoragesite at Thu, 25 Apr 2013 09:18:06 +0200 As this research shows you can’t treat customer channel preferences in isolation – people will want to use different channels at different times but do expect consistency across every interaction. Organisations need to invest in centralised knowledge to power every channel, rather than adopting a silo-based approach which will create inconsistency and waste a customer’s time. - http://pinterest.com/birthdaygift01/ at Mon, 13 May 2013 07:49:50 +0200 PURCHASE A PERSONALIZED DEED Buy for yourself or as a unique gift for your husband, Wife or child. In fact it's the perfect gift for just about anyone.