Re: [PHP] Java - toString() <-> php - ?
If you use PHP 5 just use the __toString() magic method which does exactly that. http://www.php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring Jasper Rory Browne wrote: Um - did you read my last email regarding var_dump var_export and print_r Did you try them? Do they do what you want? On 8/2/05, Adi Zebic <[EMAIL PROTECTED]> wrote: Rory Browne a écrit : I haven't a monkies what that code(your java) does, and I don't have time to analyse it(in expensive cybercafe), but you may want to consider www.php.net/print-r www.php.net/var-dump and www.php.net/var-export I think they may do what you want without using the toString method, which for what you're describing is basicly an ugly hack. One more thing: Enlighten me: What exactly do you mean by "live evolution" in your php/java context. If in php context you have class, say, A: class A { var $t1; var $t2; var $t3; //After, you have object contructor of type A //we have something like this function A ($var1, $var2, $var3) { $this -> t1 = $var1; $this -> t2 = $var2; $this -> t3 = $var3; } some other code } //than in some other class we have something like this: class someOtherClass { $aConstructor = new A(1,2,3); //values of t1, t2 and t3 are 1,2 and 3 now } Right? yes. How you can you do something like this inside of "someOtherClass" print ($aConstructor); to finally have some nice output like Value of t1 is 1; Value of t2 is 2; Value of T3 is 3; or just: 1 2 3 Without creating functions like getValues() function getValues() { print ($this -> t1); print ($this -> t2); print ($this -> t3); } and after explicit invoke function: $aConstructor -> getValues(); So, what I want is this: print ($aConstructor); and not this: $aContructor -> getValues(); Am I clear :-) ADI -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Java - toString() <-> php - ?
Um - did you read my last email regarding var_dump var_export and print_r Did you try them? Do they do what you want? On 8/2/05, Adi Zebic <[EMAIL PROTECTED]> wrote: > Rory Browne a écrit : > > I haven't a monkies what that code(your java) does, and I don't have > > time to analyse it(in expensive cybercafe), but you may want to > > consider www.php.net/print-r www.php.net/var-dump and > > www.php.net/var-export > > > > I think they may do what you want without using the toString method, > > which for what you're describing is basicly an ugly hack. > > > > One more thing: Enlighten me: What exactly do you mean by "live > > evolution" in your php/java context. > > If in php context you have class, say, A: > > class A > { > > var $t1; > var $t2; > var $t3; > > //After, you have object contructor of type A > //we have something like this > > function A ($var1, $var2, $var3) > { >$this -> t1 = $var1; >$this -> t2 = $var2; >$this -> t3 = $var3; > } > > some other code > } > > //than in some other class we have something like this: > > class someOtherClass > { >$aConstructor = new A(1,2,3); >//values of t1, t2 and t3 are 1,2 and 3 now > } > > Right? yes. > > How you can you do something like this inside of "someOtherClass" > > print ($aConstructor); > > to finally have some nice output like > Value of t1 is 1; > Value of t2 is 2; > Value of T3 is 3; > > or just: > > 1 > 2 > 3 > > Without creating functions like getValues() > > function getValues() > { >print ($this -> t1); >print ($this -> t2); >print ($this -> t3); > } > > and after explicit invoke function: > > $aConstructor -> getValues(); > > So, what I want is > this: print ($aConstructor); > > and not this: > > $aContructor -> getValues(); > > Am I clear :-) > > > ADI > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Java - toString() <-> php - ?
Rory Browne a écrit : I haven't a monkies what that code(your java) does, and I don't have time to analyse it(in expensive cybercafe), but you may want to consider www.php.net/print-r www.php.net/var-dump and www.php.net/var-export I think they may do what you want without using the toString method, which for what you're describing is basicly an ugly hack. One more thing: Enlighten me: What exactly do you mean by "live evolution" in your php/java context. If in php context you have class, say, A: class A { var $t1; var $t2; var $t3; //After, you have object contructor of type A //we have something like this function A ($var1, $var2, $var3) { $this -> t1 = $var1; $this -> t2 = $var2; $this -> t3 = $var3; } some other code } //than in some other class we have something like this: class someOtherClass { $aConstructor = new A(1,2,3); //values of t1, t2 and t3 are 1,2 and 3 now } Right? yes. How you can you do something like this inside of "someOtherClass" print ($aConstructor); to finally have some nice output like Value of t1 is 1; Value of t2 is 2; Value of T3 is 3; or just: 1 2 3 Without creating functions like getValues() function getValues() { print ($this -> t1); print ($this -> t2); print ($this -> t3); } and after explicit invoke function: $aConstructor -> getValues(); So, what I want is this: print ($aConstructor); and not this: $aContructor -> getValues(); Am I clear :-) ADI -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Java - toString() <-> php - ?
I haven't a monkies what that code(your java) does, and I don't have time to analyse it(in expensive cybercafe), but you may want to consider www.php.net/print-r www.php.net/var-dump and www.php.net/var-export I think they may do what you want without using the toString method, which for what you're describing is basicly an ugly hack. One more thing: Enlighten me: What exactly do you mean by "live evolution" in your php/java context. On 8/2/05, Adi Zebic <[EMAIL PROTECTED]> wrote: > To print "state" of object in Java I can define toString() function and > then I can do something like this: > > Java exemple: > * > import java.io.*; > import java.util.*; > > public class ReadTextFromFile > { >private static String line; >private static String Fable = new String (""); >private static String NomFable; >private static int cptLine = 0; >private static int nbrPersonnes = 0; >private static String nomPersonnes = new String (""); >private static ArrayList AListe = new ArrayList(nbrPersonnes); > > //** > public String toString() > { >return getClass().getName() >+ " [ Nom de la fable: "+ NomFable >+ " <==> Nombre de personnes dans dialogue: " + nbrPersonnes >+ " ] " >; > } > *** > > Is there similar kind of function in php that help us to print the state > of object in his "life evolution"? > > Thanks > > > ADI > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Java - toString() <-> php - ?
Adi Zebic wrote: To print "state" of object in Java I can define toString() function and then I can do something like this: Java exemple: * import java.io.*; import java.util.*; public class ReadTextFromFile { private static String line; private static String Fable = new String (""); private static String NomFable; private static int cptLine = 0; private static int nbrPersonnes = 0; private static String nomPersonnes = new String (""); private static ArrayList AListe = new ArrayList(nbrPersonnes); //** public String toString() { return getClass().getName() + " [ Nom de la fable: "+ NomFable + " <==> Nombre de personnes dans dialogue: " + nbrPersonnes + " ] " ; } *** Is there similar kind of function in php that help us to print the state of object in his "life evolution"? there is but it's use is limited and currently AFAIR it only works on internally defined classes the method is called __toString() - from what I have read and played with it (not recently though) the fucntionality is _bit_ 'halfbaked' - as in the internals guys are still pondering how to imnplement this as nicely as possible. an example: the problem with implementing this is the fact that php is dynamically typed - and it autocasts types all over the place - very handy BUT it makes a __toString() [magic] method very hard to implement in a way that is obvious to the people using it (try playing around with the SimpleXML extension to see how it can warp your brain! well it makes my head spin anyway :-) but don't take my word for it - try it yourself, oh and also take a dive into the [php]internals mailing list archives - lots has been discussed about this function AFAIR. Thanks ADI -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Java - toString() <-> php - ?
To print "state" of object in Java I can define toString() function and then I can do something like this: Java exemple: * import java.io.*; import java.util.*; public class ReadTextFromFile { private static String line; private static String Fable = new String (""); private static String NomFable; private static int cptLine = 0; private static int nbrPersonnes = 0; private static String nomPersonnes = new String (""); private static ArrayList AListe = new ArrayList(nbrPersonnes); //** public String toString() { return getClass().getName() + " [ Nom de la fable: "+ NomFable + " <==> Nombre de personnes dans dialogue: " + nbrPersonnes + " ] " ; } *** Is there similar kind of function in php that help us to print the state of object in his "life evolution"? Thanks ADI -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php