Re: [PHP] php5 - possible bug discovered
Hi Robert, Stut List Thanks for your replies which arrived after I had gone to bed |-Z Robert :- In PHP5 objects are no longer copied when assigned. Instead the object's handle is assigned (similar to a reference but not quite). So the behaviour is as expected. Stut :- I think I have discovered a bug in php5. If I haven't, I've discovered a bug in the documentation or a bug in my brain. Start here: http://php.net/language.oop5.cloning It's amazing what a good night's sleep will do :-) I could not find that page last night even though I was sure it must have existed and I can see that it is a well documented and encountered problem. My main obesrvation is that I'm glad that I decided to revisit all my old PHP4 stuff and rewrite or clean it up. I have hundreds of $Working_Class = $Under_Class; lines in my code as well as $Upper_Class = $Aristocracy; lines too. I think the documentation on references needs updating to reflect PHP 5's behaviour a little more accurately because I can see this causing serious problems to somebody just copying their code blindly. I have just built a client a development server using php5 instead of php4 and turned zend.ze1_compatibility_mode on so that their old CMS would work - I just hadn't realised that the cloning problem was solved by this. Oh well, now I'm fresh I can crack on :-) TTFN D php/general-2007-10-09.tx [EMAIL PROTECTED] [EMAIL PROTECTED] php-general ++ | Dave Restall, Computer Nerd, Cyclist, Radio Amateur G4FCU, Bodger | | Mob +44 (0) 7973 831245 Skype: dave.restall Radio: G4FCU | | email : [EMAIL PROTECTED] Web : Not Ready Yet :-( | ++ | birth, n: | | The first and direst of all disasters. | | -- Ambrose Bierce, The Devil's Dictionary| ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] php5 - possible bug discovered
Hi, I think I have discovered a bug in php5. If I haven't, I've discovered a bug in the documentation or a bug in my brain. php -v :- PHP 5.2.3 (cli) (built: Jun 26 2007 15:38:48) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies I've attached a code snippet for those that want to save it and try running it and it's also pasted here :- ?php class Class_1 { private $Text; function __construct($Text) { $this-Text = $Text; } function Set($Text) { $this-Text = $Text; } function Display() { print $this-Text . \n; } } // End Class_1 class Class_2 { private $Text; private $C1; function __construct($Text) { $this-Text = $Text; $this-C1 = new Class_1('From David'); } function Set_C1($Text) { $this-C1-Set($Text); } function Display() { print $this-Text . \n; $this-C1-Display(); } } // End Class_2 print Below is T1\n; $T1 = new Class_1('Hello'); $T1-Display(); print Below is T2\n; $T2 = new Class_2('World'); $T2-Display(); print Copying T2\n; $T3 = $T2; print T2 Copied, original value is :-\n; $T2-Display(); print Copy of T2 (T3) value is :- \n; $T3-Display(); print Changing T3\n; $T3-Set_C1(This clears Dave); print T3 Change complete, new value is :-\n; $T3-Display(); print Below is T2 which shouldn't have changed !!! \n; $T2-Display(); // var_dump($T1); ? The output it produces is :- % php -e bug.php Below is T1 Hello Below is T2 World From David Copying T2 T2 Copied, original value is :- World From David Copy of T2 (T3) value is :- World From David Changing T3 T3 Change complete, new value is :- World This clears Dave Below is T2 which shouldn't have changed !!! World This clears Dave % Now I would expect that $T2 would not change when I changed $T3. Reading the documentation :- http://www.php.net/manual/en/language.references.whatdo.php ... Note: Not using the operator causes a copy of the object to be made. If you use $this in the class it will operate on the current instance of the class. The assignment without will copy the instance (i.e. the object) and $this will operate on the copy, which is not always what is desired. Usually you want to have a single instance to work with, due to performance and memory consumption issues. This effectively states that $T3 is a 'COPY' of $T2 and $T3 works on the copy, not the master yet in the above snippet, the copy and the master have both been changed. Further documentation mentions that the copy starts off as a reference and only becomes a copy when it is changed. This doesn't seem to be happening. I found this because in my actual application I was using :- Master.class ... $Clone = $this; $Clone-Do_Something; and later in master.class I did :- $this-Do_Something_Else and php barfed with :- PHP Fatal error: Call to a member function Function_Name() on a non-object I had deleted the missing object in $Clone but not in the master (this was the whole idea of working on $Clone - I didn't want to delete the object in the master !!). I can't find anything similar in the bug database on php.net (but I may be looking in the wrong place) and I can't believe that I'm the first person to encounter this. Can anybody explain if this is a bug or if I have misunderstood the documentation ? TTFN D php/general-2007-10-08.tx php-general ++ | Dave Restall, Computer Nerd, Cyclist, Radio Amateur G4FCU, Bodger | | Mob +44 (0) 7973 831245 Skype: dave.restall Radio: G4FCU | | email : [EMAIL PROTECTED] Web : Not Ready Yet :-( | ++ | Good salesmen and good repairmen will never go hungry. | | -- R. E. Schenk| ++ bug.php Description: application/httpd-php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Includes eating up my time
Hi Dave, PHP general list, This is probably obvious to people who are good at PHP, but I'm I have a PHP based CMS (content management system) built, which has grown and become quite robust. It's now spread out over about 30 files, and each file represents one class within the object oriented design. Each are a couple hundred lines of code, and two or three of the most critical classes are over a thousand lines of code. It may just be a 'dave' thing but my stuff does that too :-) While first building it, I didn't really anticipate quite that many files. What I did is have a file called includes.php, which list all the files to be included. Then I in turn included includes.php at the beginning of my index.php file. Every page request passes through the index.php file, so that basically means every single file is included at the start of every new page request. Ahh the 'dave' thing returns :-) I'm using Zend Studio, which has a profile option, which shows how long it takes for my PHP scripts to complete a request. It has a breakdown showing percentages of which scripts are using that processing time. Real dave's use vi top :-P My second question is: Is there a systematic way of determining how to incrementally include files that people use? Or is it just a constant process of testing and checking? Thank you for any advice. What version of PHP are you using ? I moved over to 5 and it has a nice cute feature :- http://uk3.php.net/__autoload which basically only loads classes when they are required. PHP 5 has some other nice to have features and will cause you a bit of work if you migrate to it BUT it is worth the effort especially in the light of 888 :-) As for your performance problems, the times are heavily dependant on the hardware and underlying OS server load etc. without further info, diagnosing problems will be dificult. TTFN Dave php/general-2007-07-31.tx php-general [EMAIL PROTECTED] ++ | Dave Restall, Computer Nerd, Cyclist, Radio Amateur G4FCU, Bodger | | Mob +44 (0) 7973 831245 Skype: dave.restall Radio: G4FCU | | email : [EMAIL PROTECTED] Web : Not Ready Yet :-( | ++ | Big book, big bore.| | -- Callimachus | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Getting WAY OT now Re: PHP Brain Teasers
Hi, Tedd Wrote :- At 11:00 PM -0400 7/5/07, Robert Cummings wrote: On Thu, 2007-07-05 at 22:44 -0400, tedd wrote: At 4:48 PM -0400 7/5/07, Daniel Brown wrote: On 7/5/07, Robert Cummings [EMAIL PROTECTED] wrote: On Thu, 2007-07-05 at 15:04 -0500, Kaleb Pomeroy wrote: Which came first, the chicken or the egg? The egg, fish were laying them long before chickens walked the earth :) But actually, it was dinosaurs. Um... fish predate all land creatures according to evolution that's not to say something with eggs didn't predate fish, but I'm too lazy to go look. Yes, but I was talking about predecessors to the chicken, like Archeopteryx (one of the first feathered dinosaurs), which is/was (my education is dated) believed to be the predecessor of birds. As far as eggs are concerned, they predate fish considerably. As far as I'm aware, eggs don't predate anything. How could they - they don't have legs or mouths so couldn't eat anything if they could run to catch it :-) TTFN D php/general-2007-07-06.tx php-general [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] ++ | Dave Restall, Computer Nerd, Cyclist, Radio Amateur G4FCU, Bodger | | Mob +44 (0) 7973 831245 Skype: dave.restall Radio: G4FCU | | email : [EMAIL PROTECTED] Web : Not Ready Yet :-( | ++ | Mind if I smoke? | | I don't care if you burst into flames and die! | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP Brain Teasers
Hi, there are two in this one :- function Cat($Danger = ) { static int $Lives = 9; if (preg_match(/^curiosity$/i, $Danger)) die(Cat Killed); $Threats = array(dog, flu, fall, drowning); if (in_array(strtolower($Danger), $Threats)) $Lives --; if ($Lives == 0) die(No More Chances); } // Cat TTFN D php/general-2007-07-03.tx php-general ++ | Dave Restall, Computer Nerd, Cyclist, Radio Amateur G4FCU, Bodger | | Mob +44 (0) 7973 831245 Skype: dave.restall Radio: G4FCU | | email : [EMAIL PROTECTED] Web : Not Ready Yet :-( | ++ | People should have access to the data which you have about them. | | There should | | be a process for them to challenge any inaccuracies. | | -- Arthur Miller | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP Brain Teasers
Hi, Colin Guthrie wrote: Daniel Brown wrote: What the hell? Why not start a thread that can be fun and challenging for all of us. It's something I haven't seen done Here's another quickie: Dead simple one! ?php function x($x) { switch ($x) { case 1: return 'bitten'; case 2: return 'shy'; } } Surely this should be... function x() { static $count = 0; $count++; switch ($count) { case 1: return 'bitten'; case 2: return 'shy'; } return ''; } -Stut Probably a more accurate solution would be :- function x() { static $count = 0; $count++; switch ($count % 3) { case 0: case 2: return 'shy'; case 1: return 'bitten'; } } // x And it's commented :-P TTFN D php/general-2007-06-27.tx php-general ++ | Dave Restall, Computer Nerd, Cyclist, Radio Amateur G4FCU, Bodger | | Mob +44 (0) 7973 831245 Skype: dave.restall Radio: G4FCU | | email : [EMAIL PROTECTED] Web : Not Ready Yet :-( | ++ | Sooner or later you must pay for your sins. (Those who have already | | paid may disregard this cookie). | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] R: Re: [PHP] Which PHP-script crashes my server?
Hi Phil, Linux, of course. :-) It is a Gentoo server with Confixx Pro on it. The PHP safe mode is disabled for some accounts, so it is clear that problems like this happen. But I can not enable it because of several scripts. Thats all I know. I dit not setup the server. If you need some special information, tell me which one. It's not the answer but it may help you minimise rebooting, have you had a look at http://www.php.net/manual/en/ref.info.php#ini.max-execution-time ? It may be set to something odd. You could use this as a starting point. Regards, Dave php/general-2006-12-19.tx php-general [EMAIL PROTECTED] ++ | Dave Restall, Computer Nerd, Cyclist, Radio Amateur G4 FCU, Bodger | | Mob +44 (0) 7973 831245 Skype: dave.restall Radio: G4 FCU | | email : [EMAIL PROTECTED] Web : Not Ready Yet :-( | ++ | Spare no expense to save money on this one. | | -- Samuel Goldwyn | ++ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php