Re: casting static property
| From: | Jochem Maas | Date: | Sun, 31 Aug 2008 19:37:40 +0000 |
| Subject: | Re: casting static property | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-279156@lists.php.net to get a copy of this message | ||
Diogo Neves schreef:
Hi again, There's what you need ( I think )not so much that I need it, but the easier you make it for some one to look at your issue the more likely it is someone will. :-)
Simplified version for web: http://pastebin.com/d2bfcf495 Simplified version for CLI: http://pastebin.com/d6ab96ed0good stuff. only I don't get what your trying to show, exactly. seems like your confused between instance (object) properties and class (static) properties. in your example $this->e and $this->f don't exist as instance properties ... this becomes clear if you set error_reporting to include E_NOTICES. the static properties $e and $f should be referred to in code as follows: class Foo { private $d = 1; static private $e = 2; public function test() { echo "\$this->d = ", $this->d, "\nself::\$e = ", self::$e, "\n"; } } $foo = new Foo; $foo->test(); PS, another tip when writing simple test code for the CLI, always use *only* double quotes in such code ... this allows people to cut and paste the code directly onto the cmdline (not sure this will work on windows btw) e.g. $> php -r 'class Foo { static private $f = 1; function test() { echo "\$this->e = {$this->e}"; }}'
On Sun, Aug 31, 2008 at 7:09 PM, Jochem Maas <jochem@iamjochem.com> wrote:Diogo Neves schreef:Sorry, i have no webserver... but I can send all code in the email, right?you can use pastebin.com. I also recommend you write reproduce/example code like this for the CLI so that other people don't have to go throught the hassle of running via a webserver (<br /> is not very helpful in terms of readability<?php define('a', 0); $b = 0; class foo { private $c = 0; private static $e = 0; private static $f = '0'; public function techo() {echo ' direct -->' . 0 . '<br />'; echo ' a --> ' . a . '<br />'; echo ' (string)a --> ' . (string)a . '<br />'; global $b; echo ' b --> ' . $b . '<br />'; echo ' c --> ' . $this->c . '<br />'; $d = 0; echo ' d --> ' . $d . '<br />'; echo ' e --> ' . $this->e . '<br />'; // OK, static creates a reference, so? echo ' (int)e --> ' . (int)$this->e . '<br />'; echo ' (string)e --> ' . (string)$this->e . '<br />'; // What? Why? echo ' f --> ' . $this->f . '<br />'; // OK, static creates a reference, so? echo ' (int)f --> ' . (int)$this->f . '<br />'; echo ' (string)f --> ' . (string)$this->f . '<br />'; // What? Why?} public function techo2() {echo ' direct -->', 0, '<br />'; echo ' a --> ', a, '<br />'; echo ' (string)a --> ', (string)a, '<br />'; global $b; echo ' b --> ', $b, '<br />'; echo ' c --> ', $this->c, '<br />'; $d = 0; echo ' d --> ', $d, '<br />'; echo ' e --> ', $this->e, '<br />'; // OK, static creates a reference, so? echo ' (int)e --> ', (int)$this->e, '<br />'; echo ' (string)e --> ', (string)$this->e, '<br />'; // What? Why? echo ' f --> ', $this->f, '<br />'; // OK, static creates a reference, so? echo ' (int)f --> ', (int)$this->f, '<br />'; echo ' (string)f --> ', (string)$this->f, '<br />'; // What? Why?} public function techo3() {global $b; $d = 0;echo ' direct -->', 0, '<br />', ' a --> ', a, '<br />', ' (string)a --> ', (string)a, '<br />', ' b --> ', $b, '<br />', ' c --> ', $this->c, '<br />', ' d --> ', $d, '<br />', ' e --> ', $this->e, '<br />', // OK, static creates a reference, so? ' (int)e --> ', (int)$this->e, '<br />', ' (string)e --> ', (string)$this->e, '<br />', // What? Why? ' f --> ', $this->f, '<br />', // OK, static creates a reference, so? ' (int)f --> ', (int)$this->f, '<br />', ' (string)f --> ', (string)$this->f, '<br />'; // What? Why?} } $foo = new foo( ); function mytime( ) {$time = microtime( ); $time = explode( " ", $time ); $time = $time[1] + $time[0]; return $time;} $time1 = mytime( ); $foo->techo( ); $time2 = mytime( ); $totaltime = ($time2 - $time1); echo '<br /><br />techo() --> ', $totaltime, '<br /><br /><br />'; $time1 = mytime( ); $foo->techo2( ); $time2 = mytime( ); $totaltime = ($time2 - $time1); echo '<br /><br />techo2() --> ', $totaltime, '<br /><br /><br />'; $time1 = mytime( ); $foo->techo3( ); $time2 = mytime( ); $totaltime = ($time2 - $time1); echo '<br /><br />techo2() --> ', $totaltime, '<br /><br /><br />'; ?> I believe yes On Sun, Aug 31, 2008 at 5:37 PM, Robert Cummings <robert@interjinn.com> wrote:On Sun, 2008-08-31 at 17:09 +0200, Jochem Maas wrote:Diogo Neves schreef:Hi all, Why a static var don't cast as a dynamic one? See file for more info...attachments get stripped. don't cross post to internals, it's bad form. try and formulate your questions a bit better (it should take you more time to write your post than it takes for someone else to figure out what your going on about.).give a man fish. Diogo already succeeded in sending a text attachment in a previous post ... I figured I let him work it out for himself ;-) .... you pedantic **** :-DCorrection, text attachments don't get stripped.Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP