Re: Java - toString() <-> php - ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <adi@xxxxxxxxxxxx> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux