a) I don't see how the part about the "dot notation" has anything to do with the class presetned b) I don't see any benefit to the class presented c) Trying to follow the chain of -> operators and method calls just gave me a headache. Other than that, it's really nifty. :-v On Thu, April 12, 2007 1:22 am, Jim Lucas wrote: > Ok, I have seen many different examples of OOP, but nothing quite like > this. > > Someone was showing me syntax for Ruby the other day, and it got me > thinking, wouldn't it be neat to > imitate ruby, or be it a little more generic, dot notation for OOP > ways of calling methods like > Java, javascript, ruby and others. So I came up with this. > > Seems to work in PHP5, but chokes in PHP4. > > I would like input on this setup for calling methods. > > <plaintext><?php > > class myString { > private $value = ''; > function __construct() { > } > function in($str=null) { > if ( is_null($str) ) { > echo "A string wasn't given."; > exit; > } > $this->value = $str; > $this->setProperties(); > return $this; > } > function out() { > echo $this->value; > } > function get() { > return $this->value; > } > function append($a) { > $this->value = $this->value.$a; > $this->setProperties(); > return $this; > } > function prepend($a) { > $this->value = $a.$this->value; > $this->setProperties(); > return $this; > } > function regex_replace($from, $to) { > $this->value = preg_replace("!{$from}!", $to, $this->value); > $this->setProperties(); > return $this; > } > function setProperties() { > $this->str_length = strlen($this->value); > return $this; > } > function length() { > return $this->str_length; > } > } > > $str = new myString; > > echo $str->in("Starting String!")->prepend("Second > String!")->regex_replace(' ', '_')->get(); > echo $str->length(); > $str->in("A new string")->out(); > > ?> > > Has anybody else seen this style of syntax? > > Have they used this style of syntax? > > If so, what is your opinion of this style? > > TIA > Jim > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php