jordanwb Posted September 23, 2008 Share Posted September 23, 2008 class Foo { public static function Bar () { return "Hello World!"; } } $foo = new Foo (); print $foo->Bar (); Output: Hello World! Why does this happen? Why does PHP turn the static function into an instance function. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 23, 2008 Share Posted September 23, 2008 Because you can technically call the static method from an instance as long as you don't use any $this stuff. If you don't want to be able to do that, just do something like: <?php class Foo { private function __construct() { } //no initializations! public static function Test() { return "Testing worked!"; } } Foo::Test(); //works $foo = new Foo; //errors out! $foo->Test(); //doesn't even get up to here Quote Link to comment Share on other sites More sharing options...
corbin Posted September 24, 2008 Share Posted September 24, 2008 In PHP6, I think they decided to throw a fatal error on dynamic calling of a static function. Maybe it's a warning or something, but I know they decided to make it [like it should be] a no-no. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 In PHP6, I think they decided to throw a fatal error on dynamic calling of a static function. Maybe it's a warning or something, but I know they decided to make it [like it should be] a no-no. Yup, they fixed it in PHP6 if I remember correctly. Quote Link to comment Share on other sites More sharing options...
jordanwb Posted September 25, 2008 Author Share Posted September 25, 2008 Certainly took them long enough to figure out what was supposed to happen. OOP Fail. This forum failed a whole bunch of times just to make this message. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 25, 2008 Share Posted September 25, 2008 Certainly took them long enough to figure out what was supposed to happen. OOP Fail. This forum failed a whole bunch of times just to make this message. lolwut? Quote Link to comment Share on other sites More sharing options...
jordanwb Posted September 25, 2008 Author Share Posted September 25, 2008 lolwut? The first time I tried to post the forum said that I had already made a post with my IP (or something retarded like that), then I got the same message a second time. Then it said that I had already posted the same message (WTFail?) and I didn't. So I had to wait about a minute before the forum would let me post. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 25, 2008 Share Posted September 25, 2008 It restarts the 25-second timer when you try to make a post in the 25-second time period, I think. Quote Link to comment Share on other sites More sharing options...
jordanwb Posted September 25, 2008 Author Share Posted September 25, 2008 It restarts the 25-second timer when you try to make a post in the 25-second time period, I think. But I didn't, what you said "lolwut?" to was the first post I made today. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 25, 2008 Share Posted September 25, 2008 Ha, sucks for you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.