__toString()

thread: 3 messages  |  last: about 5 years ago  |  started: tuesday, september 5, 2006, 2:26 pm pdt


#1  |  Chris Peterson (Seattle, WA) United States of America Qcodo Core Contributor
Tuesday, September 5, 2006, 2:26 PM PDT

I was wondering about peoples thoughts of adding a __toString() function to the Qcontrol.   i was implmenting an array of Qobjects, i.e.  QTextBox, QListBox, QDateTime, etc.. and saw a need for it in my app.  

for me I was having it render values and I was thinking in the cases of QListControls it would cycle through objects that are selected and return a comma or space delemited string, on the textbox it would return $obj->Text and on QDateTime return the __toString method from it.

obviously it would be overrideable by each control and depending on how it would function in the app.

i added it to mine already, but just wondering if that was something that the community might like to see.  Java has a lot of the __toString method so maybe i am just used to using it to often and need to find another way.

#2  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Tuesday, September 5, 2006, 4:26 PM PDT

an interesting thought... but i'm worried, would it be confusing at all?

For some people, it might make sense that __toString() on a textbox would give you the text contents of that textbox.  But for others, would they think __toString() would give you the rendered html of that same textbox control?

#3  |  Chris Peterson (Seattle, WA) United States of America Qcodo Core Contributor
Thursday, September 7, 2006, 4:18 PM PDT

Yea I had thought about that, which is why i was throwing it out for discussion.  

My thought is that _toString wouldn't contain rendered content, i.e. html code.  but that is obviously a bias opinion.  i wouldn't mind overriding the __toString() method to contain the values that I needed, but was thinking that there should be some overrideable method that was consistent across the Qobjects, that would allow me to pull the values or text needed.  I couldn't really override, the ->Name and ->Text variables, because that would affect the display and results of my object.  

I was thinking that something like   __toString() could be the consistent overridable method that could be globally used.  maybe something like ValueOf()

here is what the java docs say on their use of _toString

toString

public String toString() - Returns a string representation of the object. In general, the toString method returns a string that “textually represents” this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

getClass().getName() + '@' + Integer.toHexString(hashCode())

Returns:
a string representation of the object.


anyway.. just a thought. =)



Copyright © 2005 - 2012, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.