Re: [PHP] Re: Copying an Object
On Fri, Sep 24, 2010 at 4:09 AM, Gary wrote: > Daniel Kolbo wrote: > >> Say you have two classes: human and male. Further, say male extends >> human. Let's say you have a human object. Then later you want to make >> that human object a male object. This seems to be a pretty reasonable >> thing to request of our objects. > > I don't think any human can change gender without major surgery, but I > don't know if you just chose your example badly or whether you really > think objects should be able to mutate into other types of object > without some kind of special treatment. But it would work in something like makehuman, where you start with a neuter form and scale one way or the other for physical features. If I remember correctly, we're' all xx until you become xy(genetically speaking). > >> This type of thing would especially be >> easy if objects of parent classes could be cast as an object of its >> extended class. > > Where would the extra data come from to fill in any fields the base > class does not have? Just think of a simple example with a Shape class, > extended by a ColouredShape class which contains some data about the > object's colour - if you have a Shape object it can't become a > ColouredShape without some surgery because bits of the ColouredShape's > anatomy are not present. > > -- > Gary Please do NOT send me 'courtesy' replies off-list. > PHP 5.2.12 (cli) (built: Jan 14 2010 14:54:11) > 1.7.7(0.230/5/3) 2010-08-31 09:58 Cygwin > > > -- > 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
[PHP] Heredocs, print_r() and newline "\n" and fnmatch() - curious failures ...
This code is 95% cut and paste from the PHP manual examples - the Types/Strings/Heredocs section and the Filesystem/fnmatch pages. There are actually two questions here - I have combined the code into one test file ... the strings in the code contain the questions .. at the end I have inserted the output I get from the code - identical in Firefox and IE8 (so it's not browser related), and on my desktop as well as my laptop (so it's not a machine quirk). The setup is Xammplite Win32-1.7.1 with PHP 5.2.9 and Apache 2.2.11 on both WinXP-SP3 installs. I tried Xammp Win32-1.7.3 with the same results. Then I tried installing Apache and PHP and MySQL individually, and got the same ... Aside from the issue here, I also was unable to get imagick and xdebug running on the same installation - it was one or the other. imagick's readfile() caused Apache to baulk on PHP5.3.3, so I returned to a fresh Xammplite setup. Same results. I have spent many hours with this - I would appreciate some insight .. Question 1 : how to get the newline functioning ? even print_r() output is not 'newlined' as it should be. Also note the \n is missing between the " " in the output text of the second test! Question 2 : fnmatch() is an internal function (ie built in to PHP, yet get_defined_functions() does not find it. Perhaps there are others also missing, I haven't done a check - could it be a compile error in Xammplite's PHP binaries? - heredoctest.php = the // comments are not in the actual file ... - foo = 'Foo'; $this->bar = array('Bar1', 'Bar2', 'Bar3'); } } $foo = new foo(); $name = 'MyName'; echo <bar[1]}. This should print a capital 'A': \x41 EOT; // again no newlines on direct heredoc echo ... echo << - Here's the output: - the line breaks are non-existent - here, of course the wrapping is imposed by the mail client editor, but in the browser it just it all just runs together .. most curious, very frustrating. - Example of string spanning multiple lines using heredoc syntax. (this code cut and paste from the PHP manual examples ... it just will not work ...! My name is "MyName". I am printing some Foo. Now, I am printing some Bar2. This should print a capital 'A': Aa second test for newlines - " " - can't find what is required to get this to work - have tried everything in the PHP Manual - still nothing - amazingly even Heredocs does not work. Tried this on two machines - both running Xammplite 1.7.1. Also tried installing PHP5.3.3 - and Newdocs doesn't work either. Any ideas?some form of gray ... ... or grey Fatal error: Call to undefined function fnmatch() in C:\xammplite\htdocs\heredoctest.php on line 47 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Database Administration
On 22 September 2010 21:40, Bastien Koert wrote: > Not at all. What I would suggest is that you create a separate mysql > user that is used exclusively by the script to do the create stuff. > The regular application user account should not have those privileges > at all. > I'm not actually that familiar with DB admin to that extent. I have either app users with lock+crud on specific databases, or root. As a an aside, would you know if there is a level of permissions for a user between app and root that would be 'sensibly secure' (it will be MySQL 5)? > Another option, if immediate response is not required, is to save this > data into the system for a cron script with another user account to > run. > This was sort of my first instinct. I ponder writing a small daemon/cron that queries a database table (client list) and does all the 'build' bits. The main issue with cron is that the users would want a fairly immediate response. Seconds is acceptable, but a 5 minute cron might be too slow. > Is there a reason for you not to place all the data in one DB and just > separate them out based on user id, to ensure they only see their own > data > For legal reasons. Each client must have separate data. I need to be able to box up all the client data (containing multiple app instances) and be 100% sure that I am giving them all their data and nobody else's. On 23 September 2010 18:04, tedd wrote: > No, but from what you've said, I don't think the end user must have > privileges and the ability to create a database and tables. It sounds more > like allowing the user to set up his own admin for acceptable users -- > there's a big difference. > > So, what you need to define is what the client and his users want to do. > From that, we can determine what they need. Depending on what you mean by 'the client', all the client side things are fine :) The web front-end I am working on here is for internal use only. To allow non-technical people to set up clients and their apps. The more I look into this, the more I am leaning towards some shell scripts for client management, invoking them by cron. Then if an immediate response is needed someone technical will have to manually run the cron job. It looks like the law of diminishing returns for me to build something really usable.
Re: [PHP] Heredocs, print_r() and newline "\n" and fnmatch() - curious failures ...
On 23 September 2010 21:47, YAD(YetAnotherDavid) wrote: > This code is 95% cut and paste from the PHP manual examples - > the Types/Strings/Heredocs section and the Filesystem/fnmatch pages. > There are actually two questions here - I have combined the code into one > test file ... the strings in the code contain the questions .. > at the end I have inserted the output I get from the code - identical in > Firefox and IE8 (so it's not browser related), and on my desktop as well as > my laptop (so it's not a machine quirk). The setup is Xammplite Win32-1.7.1 > with PHP 5.2.9 and Apache 2.2.11 on both WinXP-SP3 installs. > > I tried Xammp Win32-1.7.3 with the same results. Then I tried installing > Apache and PHP and MySQL individually, and got the same ... > Aside from the issue here, I also was unable to get imagick and xdebug > running on the same installation - it was one or the other. imagick's > readfile() caused Apache to baulk on PHP5.3.3, so I returned to a fresh > Xammplite setup. Same results. > > I have spent many hours with this - I would appreciate some insight .. > > Question 1 : how to get the newline functioning ? even print_r() output > is not 'newlined' as it should be. Also note the \n is missing between the " > " in the output text of the second test! > Are you outputting to browser or to command line? Browsers have a habit of ignoring whitespaces, reducing them to one whitespace character regardless of their type or how many. Regards Peter -- WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: Copying an Object
From: David Hutto > On Fri, Sep 24, 2010 at 4:09 AM, Gary wrote: >> Daniel Kolbo wrote: >> >>> Say you have two classes: human and male. Further, say male extends >>> human. Let's say you have a human object. Then later you want to make >>> that human object a male object. This seems to be a pretty reasonable >>> thing to request of our objects. >> >> I don't think any human can change gender without major surgery, but I >> don't know if you just chose your example badly or whether you really >> think objects should be able to mutate into other types of object >> without some kind of special treatment. > > But it would work in something like makehuman, where you start with a neuter > form and scale one way or the other for physical features. If I > remember correctly, > we're' all xx until you become xy(genetically speaking). This is one of the details that really bothers me about OOP. It makes it impossible to implement some very reasonable scenarios. 80% of the time, when a patron is added to a system, we don't know which gender they are. More than 50% of the time, we will never know, since the client doesn't keep track of it. But the rest of them will be assigned sometime after they were added. i.e. the gender assignment comes from a secondary source that is not available at the time the patron is entered. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Copying an Object
On 24 September 2010 14:22, Bob McConnell wrote: > From: David Hutto > >> On Fri, Sep 24, 2010 at 4:09 AM, Gary wrote: >>> Daniel Kolbo wrote: >>> Say you have two classes: human and male. Further, say male extends human. Let's say you have a human object. Then later you want to make that human object a male object. This seems to be a pretty reasonable thing to request of our objects. >>> >>> I don't think any human can change gender without major surgery, but I >>> don't know if you just chose your example badly or whether you really >>> think objects should be able to mutate into other types of object >>> without some kind of special treatment. >> >> But it would work in something like makehuman, where you start with a neuter >> form and scale one way or the other for physical features. If I >> remember correctly, >> we're' all xx until you become xy(genetically speaking). > > This is one of the details that really bothers me about OOP. It makes it > impossible to implement some very reasonable scenarios. 80% of the time, when > a patron is added to a system, we don't know which gender they are. More than > 50% of the time, we will never know, since the client doesn't keep track of > it. But the rest of them will be assigned sometime after they were added. > i.e. the gender assignment comes from a secondary source that is not > available at the time the patron is entered. > If you can't handle that, it's not the fault of OOP but your lack of programming skills in OOP I'd say (and I mean no disrespect there, I'm just pretty sure your scenario can be handled very easily in OOP). And no, I have no urge to defend OOP in PHP, I just see this entire thread as a complete non-starter: if the language doesn't let you do something in a particular way, how about you stop, take a breather, then ask if perhaps there's a better way in the language to do what you want done? That would normally be a much more productive and intelligent response than either a) pressing on in the face of failure or b) complaining about your specific needs and how the language fails to meet them. Regards Peter -- WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Heredocs, print_r() and newline "\n" and fnmatch() - curious failures ...
As far as I know, you wont get any line breaks. I would suggest putting the results into tags to preserve formatting. whenever I do a print_r(), i also encapsulate it within a tag so it is readable. on another note, when I use variables within double quotes "" (or even the heredoc (but i use smarty templates instead)), I always wrap them in curly braces {} as that is "suggested" (and I personally think should be required). Steve On Thu, 2010-09-23 at 21:47 +0200, YAD(YetAnotherDavid) wrote: > This code is 95% cut and paste from the PHP manual examples - > the Types/Strings/Heredocs section and the Filesystem/fnmatch pages. > There are actually two questions here - I have combined the code into > one test file ... the strings in the code contain the questions .. > at the end I have inserted the output I get from the code - identical in > Firefox and IE8 (so it's not browser related), and on my desktop as well > as my laptop (so it's not a machine quirk). The setup is Xammplite > Win32-1.7.1 with PHP 5.2.9 and Apache 2.2.11 on both WinXP-SP3 installs. > > I tried Xammp Win32-1.7.3 with the same results. Then I tried installing > Apache and PHP and MySQL individually, and got the same ... > Aside from the issue here, I also was unable to get imagick and xdebug > running on the same installation - it was one or the other. imagick's > readfile() caused Apache to baulk on PHP5.3.3, so I returned to a fresh > Xammplite setup. Same results. > > I have spent many hours with this - I would appreciate some insight .. > > Question 1 : how to get the newline functioning ? even print_r() > output is not 'newlined' as it should be. Also note the \n is missing > between the " " in the output text of the second test! > > Question 2 : fnmatch() is an internal function (ie built in to PHP, yet > get_defined_functions() does not find it. Perhaps there are others also > missing, I haven't done a check - could it be a compile error in > Xammplite's PHP binaries? > > - > heredoctest.php = the // comments are not in the actual file ... > - > $str = << Example of string > spanning multiple lines > using heredoc syntax. > (this code cut and paste from > the PHP manual examples ... > it just will not work ...! > EOD; > echo $str . "\n";//echoes the string, fails on newlines in heredoc > // content and in this newline > > /* More complex example, with variables. */ > class foo > { > var $foo; > var $bar; > > function foo() > { > $this->foo = 'Foo'; > $this->bar = array('Bar1', 'Bar2', 'Bar3'); > } > } > > $foo = new foo(); > $name = 'MyName'; > > echo << My name is "$name". I am printing some $foo->foo. > Now, I am printing some {$foo->bar[1]}. > This should print a capital 'A': \x41 > EOT; > // again no newlines on direct heredoc echo ... > > echo << a second test for newlines - "\n" - can't find what is required to > get this to work - have tried everything in the PHP Manual > - still nothing - amazingly even Heredocs does not work. > Tried this on two machines - both running Xammplite 1.7.1. Also > tried installing PHP5.3.3 - and Newdocs doesn't work either. Any ideas? > HDOC; > > //note the n gets escaped, but no actual newline occurs in the output > // and the " " gets left in the output! > > /* And for good measure, here is another bit of frustration - also > code copied directly from the manual ... > 'fnmatch' is an internal function - yet PHP can't find it ... */ > > echo "some form of gray ...\n ... or grey"; // no newline in output > > if (fnmatch("*gr[ae]y", $color)) {// function undefined, dies >echo "some form of gray ...\n ... or grey"; >} > ?> > > - > Here's the output: - the line breaks are non-existent - here, of course > the wrapping is imposed by the mail client editor, but in the browser it > just it all just runs together .. most curious, very frustrating. > - > > Example of string spanning multiple lines using heredoc syntax. (this > code cut and paste from the PHP manual examples ... it just will not > work ...! My name is "MyName". I am printing some Foo. Now, I am > printing some Bar2. This should print a capital 'A': Aa second test for > newlines - " " - can't find what is required to get this to work - have > tried everything in the PHP Manual - still nothing - amazingly even > Heredocs does not work. Tried this on two machines - both running > Xammplite 1.7.1. Also tried installing PHP5.3.3 - and Newdocs doesn't > work either. Any ideas?some form of gray ... ... or grey > Fatal error: Call to undefined function fnmatch() in > C:\xammplite\htdocs\heredoctest.php on line 47 > -- PHP Gen
RE: [PHP] Re: Copying an Object
From: Peter Lind > On 24 September 2010 14:22, Bob McConnell wrote: >> From: David Hutto >> >>> On Fri, Sep 24, 2010 at 4:09 AM, Gary wrote: Daniel Kolbo wrote: > Say you have two classes: human and male. Further, say male extends > human. Let's say you have a human object. Then later you want to make > that human object a male object. This seems to be a pretty reasonable > thing to request of our objects. I don't think any human can change gender without major surgery, but I don't know if you just chose your example badly or whether you really think objects should be able to mutate into other types of object without some kind of special treatment. >>> >>> But it would work in something like makehuman, where you start with a neuter >>> form and scale one way or the other for physical features. If I >>> remember correctly, >>> we're' all xx until you become xy(genetically speaking). >> >> This is one of the details that really bothers me about OOP. It makes > it impossible to implement some very reasonable scenarios. 80% of the > time, when a patron is added to a system, we don't know which gender > they are. More than 50% of the time, we will never know, since the > client doesn't keep track of it. But the rest of them will be assigned > sometime after they were added. i.e. the gender assignment comes from > a secondary source that is not available at the time the patron is > entered. >> > > If you can't handle that, it's not the fault of OOP but your lack of > programming skills in OOP I'd say (and I mean no disrespect there, I'm > just pretty sure your scenario can be handled very easily in OOP). > > And no, I have no urge to defend OOP in PHP, I just see this entire > thread as a complete non-starter: if the language doesn't let you do > something in a particular way, how about you stop, take a breather, > then ask if perhaps there's a better way in the language to do what > you want done? That would normally be a much more productive and > intelligent response than either a) pressing on in the face of failure > or b) complaining about your specific needs and how the language fails > to meet them. I have no problem with that idea. My first reaction would be to return to a procedural format and forget about objects altogether. I have been struggling with them for more than ten years now, and still don't understand the intent or purpose behind them. They simply appear to be a lot of unnecessary overhead with no real advantages in return. Even multi-tasking was a lot easier to figure out. Unfortunately, I keep getting stuck working with other people's applications that are already cast in objects. It makes me wish I could take early retirement this winter. Sorry for the rant. I'll go hide in the corner and be quiet for a while. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Copying an Object
On Fri, Sep 24, 2010 at 8:35 AM, Peter Lind wrote: > On 24 September 2010 14:22, Bob McConnell wrote: > > From: David Hutto > > > >> On Fri, Sep 24, 2010 at 4:09 AM, Gary > wrote: > >>> Daniel Kolbo wrote: > >>> > Say you have two classes: human and male. Further, say male extends > human. Let's say you have a human object. Then later you want to > make > that human object a male object. This seems to be a pretty reasonable > thing to request of our objects. > >>> > >>> I don't think any human can change gender without major surgery, but I > >>> don't know if you just chose your example badly or whether you really > >>> think objects should be able to mutate into other types of object > >>> without some kind of special treatment. > >> > >> But it would work in something like makehuman, where you start with a > neuter > >> form and scale one way or the other for physical features. If I > >> remember correctly, > >> we're' all xx until you become xy(genetically speaking). > > > > This is one of the details that really bothers me about OOP. It makes it > impossible to implement some very reasonable scenarios. 80% of the time, > when a patron is added to a system, we don't know which gender they are. > More than 50% of the time, we will never know, since the client doesn't keep > track of it. But the rest of them will be assigned sometime after they were > added. i.e. the gender assignment comes from a secondary source that is not > available at the time the patron is entered. > > > > If you can't handle that, it's not the fault of OOP but your lack of > programming skills in OOP I'd say (and I mean no disrespect there, I'm > just pretty sure your scenario can be handled very easily in OOP). > > And no, I have no urge to defend OOP in PHP, I just see this entire > thread as a complete non-starter: if the language doesn't let you do > something in a particular way, how about you stop, take a breather, > then ask if perhaps there's a better way in the language to do what > you want done? That would normally be a much more productive and > intelligent response than either a) pressing on in the face of failure > or b) complaining about your specific needs and how the language fails > to meet them. > > Regards > Peter > > -- > > WWW: http://plphp.dk / http://plind.dk > LinkedIn: http://www.linkedin.com/in/plind > BeWelcome/Couchsurfing: Fake51 > Twitter: http://twitter.com/kafe15 > > > I think pages 17-19 of the GoF covers exactly this: "Object composition is an alternative to inheritance." ... "Any [composed] object can be replaced at run-time by another as long as it has the same type." I would look into "object composition" or just read the GoF.
RE: [PHP] Re: Copying an Object
From: chris h > On Fri, Sep 24, 2010 at 8:35 AM, Peter Lind wrote: > > On 24 September 2010 14:22, Bob McConnell wrote: > > From: David Hutto > > > >> On Fri, Sep 24, 2010 at 4:09 AM, Gary wrote: > >>> Daniel Kolbo wrote: > >>> > Say you have two classes: human and male. Further, say male extends > human. Let's say you have a human object. Then later you want to make > that human object a male object. This seems to be a pretty reasonable > thing to request of our objects. > >>> > >>> I don't think any human can change gender without major surgery, but I > >>> don't know if you just chose your example badly or whether you really > >>> think objects should be able to mutate into other types of object > >>> without some kind of special treatment. > >> > >> But it would work in something like makehuman, where you start with a neuter > >> form and scale one way or the other for physical features. If I > >> remember correctly, > >> we're' all xx until you become xy(genetically speaking). > > > > This is one of the details that really bothers me about OOP. It makes > it impossible to implement some very reasonable scenarios. 80% of the time, > when a patron is added to a system, we don't know which gender they are. > More than 50% of the time, we will never know, since the client doesn't keep > track of it. But the rest of them will be assigned sometime after they were > added. i.e. the gender assignment comes from a secondary source that is not > available at the time the patron is entered. > > > If you can't handle that, it's not the fault of OOP but your lack of > programming skills in OOP I'd say (and I mean no disrespect there, I'm > just pretty sure your scenario can be handled very easily in OOP). > > And no, I have no urge to defend OOP in PHP, I just see this entire > thread as a complete non-starter: if the language doesn't let you do > something in a particular way, how about you stop, take a breather, > then ask if perhaps there's a better way in the language to do what > you want done? That would normally be a much more productive and > intelligent response than either a) pressing on in the face of failure > or b) complaining about your specific needs and how the language fails > to meet them. > > I think pages 17-19 of the GoF covers exactly this: > > "Object composition is an alternative to inheritance." ... "Any > [composed] object can be replaced at run-time by another as long > as it has the same type." > > I would look into "object composition" or just read the GoF. GoF? Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Copying an Object
"Gang of Four" http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612 An excellent book on OOP. Chris H. On Fri, Sep 24, 2010 at 9:34 AM, Bob McConnell wrote: > From: chris h > > > On Fri, Sep 24, 2010 at 8:35 AM, Peter Lind > wrote: > > > > On 24 September 2010 14:22, Bob McConnell wrote: > > > From: David Hutto > > > > > >> On Fri, Sep 24, 2010 at 4:09 AM, Gary > wrote: > > >>> Daniel Kolbo wrote: > > >>> > > Say you have two classes: human and male. Further, say > male extends > > human. Let's say you have a human object. Then later you > want to make > > that human object a male object. This seems to be a pretty > reasonable > > thing to request of our objects. > > >>> > > >>> I don't think any human can change gender without major > surgery, but I > > >>> don't know if you just chose your example badly or whether > you really > > >>> think objects should be able to mutate into other types of > object > > >>> without some kind of special treatment. > > >> > > >> But it would work in something like makehuman, where you > start with a neuter > > >> form and scale one way or the other for physical features. If > I > > >> remember correctly, > > >> we're' all xx until you become xy(genetically speaking). > > > > > > This is one of the details that really bothers me about OOP. > It makes > > it impossible to implement some very reasonable scenarios. 80% of the > time, > > when a patron is added to a system, we don't know which gender they > are. > > More than 50% of the time, we will never know, since the client > doesn't keep > > track of it. But the rest of them will be assigned sometime after they > were > > added. i.e. the gender assignment comes from a secondary source that > is not > > available at the time the patron is entered. > > > > > If you can't handle that, it's not the fault of OOP but your > lack of > > programming skills in OOP I'd say (and I mean no disrespect > there, I'm > > just pretty sure your scenario can be handled very easily in > OOP). > > > > And no, I have no urge to defend OOP in PHP, I just see this > entire > > thread as a complete non-starter: if the language doesn't let > you do > > something in a particular way, how about you stop, take a > breather, > > then ask if perhaps there's a better way in the language to do > what > > you want done? That would normally be a much more productive and > > intelligent response than either a) pressing on in the face of > failure > > or b) complaining about your specific needs and how the language > fails > > to meet them. > > > > I think pages 17-19 of the GoF covers exactly this: > > > > "Object composition is an alternative to inheritance." ... "Any > > [composed] object can be replaced at run-time by another as long > > as it has the same type." > > > > I would look into "object composition" or just read the GoF. > > GoF? > > Bob McConnell > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Database Administration
On Fri, Sep 24, 2010 at 6:19 AM, Tom Barrett wrote: [snip] > I'm not actually that familiar with DB admin to that extent. I have either > app users with lock+crud on specific databases, or root. As a an aside, > would you know if there is a level of permissions for a user between app and > root that would be 'sensibly secure' (it will be MySQL 5)? It depends on the app, but phrases like 'sensibly secure' raise caution flags for me. I tend to go with the principle of least privilege. Where I currently work, the admin functions for a web application are usually on an intranet site that is completely separate from the public site. Because of this, I have a different database user for each site. In this case, these are database-only logins unrelated in any way to the actual machine account used by the web servers. On our newer development, nearly all table access is managed strictly through stored procedures (we use SQL Server, but the same would work for MySQL if you were so inclined), and each database user is only granted execute permission on the specific procedures necessary for that role. The only time we grant access directly to a table is in cases where we just can't get a procedure to do what we need efficiently or effectively. And, in those cases where I do need to grant access to a table, I grant permission to only the columns/operations necessary for that user. If I encountered a case where I needed to allow a user to make schema changes as you mentioned in your original post, I would create a totally separate account -- again with no more permission than necessary for its intended task. Depending on the needs of the application, I'd decide whether that account was used by the web server or via a script scheduled to execute at intervals as several others have suggested in this thread. I've not tried this, but you could probably write the logic needed to create the database objects into a stored procedure. Then, you might only need to grant permission to that procedure and not grant permission to CREATE/ALTER anything. That would pretty well guarantee that the only objects created are the ones you intended. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Copying an Object
On Thu, Sep 23, 2010 at 12:24 AM, Peter Lind wrote: > On 23 September 2010 02:14, Daniel Kolbo wrote: > > *snip* > > > On 9/22/2010 9:11 AM, chris h wrote: > > Say you have two classes: human and male. Further, say male extends > > human. Let's say you have a human object. Then later you want to make > > that human object a male object. This seems to be a pretty reasonable > > thing to request of our objects. > > Perhaps if you're a C# programmer, but the PHP way of thinking is > radically different. > C#: This object is whatever it was currently cast to (if possible) > PHP: This object is this object, whatever it was created as > > If you have a need to make an object switch class in PHP, then there's > a 99% chance you're working against, not with the language. > +1, its more like the java paradigm than anything else afaict. maybe javascript? didnt know you could change class at runtime in c#, but then again my knowledge of the .net platform is very, very minimal, and happily so :) getting to some of the other posts in the thread and trying to find a reasonable place to address them, id like to point out that this scenario (turning a human into a male) is easily modeled w/ composition in oop. class Human { // member vars & functions here } class Male { $human = null; // Human instance __construct(Human $human) { $this->human = $human; } } javascript uses a form of inheritance called prototypical inheritance. http://en.wikipedia.org/wiki/Prototype-based_programming and other languages that support runtime class alteration (ruby, python, objc etc.) are quite different than the single inheritance model in php. that said, there are ways of modeling this problem in any of these languages (see above for 1 reasonable solution w/ single inheritance in php). one of the problems w/ the runtime class alteration model is how do you determine the class of an object after altering it at runtime? -nathan
[PHP] if/elseif being treated as if/if
Hey folks, Here's the deal. I have the following code: if($col_vals[$i][$val['column']] == $search_result[0][$col]) { echo ' selected="selected"'; } elseif($val['default'] == $col_vals[$i][$val['column']]) { echo ' selected="selected"'; } It's supposed to check whether there's a value in the db ($search_result[0][$col]) that matches the current column value, and if not, check whether the default matches it. It does that, sort of. In fact, both statements trigger, which I would have said wasn't possible. So the question is: what causes both parts of an if/elseif statement to trigger? As far as I can see my punctuation is correct, and I've confirmed through debugging statements that all the values are what I expect, so how do I make the elseif stop acting like another if? Or, alternatively, have I just misunderstood all this time what the if/elseif statement does? Thanks, Alex -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if/elseif being treated as if/if
Andy I see no reason why both echo's would fire; unless this block of code gets executed multiple times. can we see more of the code? Chris H. On Fri, Sep 24, 2010 at 1:50 PM, Andy McKenzie wrote: > Hey folks, > > Here's the deal. I have the following code: > > if($col_vals[$i][$val['column']] == $search_result[0][$col]) > { echo ' selected="selected"'; } > elseif($val['default'] == $col_vals[$i][$val['column']]) > { echo ' selected="selected"'; } > > It's supposed to check whether there's a value in the db > ($search_result[0][$col]) that matches the current column value, and > if not, check whether the default matches it. It does that, sort of. > In fact, both statements trigger, which I would have said wasn't > possible. > > So the question is: what causes both parts of an if/elseif > statement to trigger? As far as I can see my punctuation is correct, > and I've confirmed through debugging statements that all the values > are what I expect, so how do I make the elseif stop acting like > another if? Or, alternatively, have I just misunderstood all this > time what the if/elseif statement does? > > Thanks, > Alex > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] if/elseif being treated as if/if
if(1 == 1){ echo 'here'; } elseif(1 == 1){ echo 'here"'; } Will only echo "here" once. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Database Administration
At 11:19 AM +0100 9/24/10, Tom Barrett wrote: On 22 September 2010 21:40, Bastien Koert wrote: Not at all. What I would suggest is that you create a separate mysql user that is used exclusively by the script to do the create stuff. The regular application user account should not have those privileges at all. I'm not actually that familiar with DB admin to that extent. I have either app users with lock+crud on specific databases, or root. As a an aside, would you know if there is a level of permissions for a user between app and root that would be 'sensibly secure' (it will be MySQL 5)? Another option, if immediate response is not required, is to save this data into the system for a cron script with another user account to run. This was sort of my first instinct. I ponder writing a small daemon/cron that queries a database table (client list) and does all the 'build' bits. The main issue with cron is that the users would want a fairly immediate response. Seconds is acceptable, but a 5 minute cron might be too slow. Is there a reason for you not to place all the data in one DB and just separate them out based on user id, to ensure they only see their own data For legal reasons. Each client must have separate data. I need to be able to box up all the client data (containing multiple app instances) and be 100% sure that I am giving them all their data and nobody else's. On 23 September 2010 18:04, tedd wrote: No, but from what you've said, I don't think the end user must have privileges and the ability to create a database and tables. It sounds more like allowing the user to set up his own admin for acceptable users -- there's a big difference. So, what you need to define is what the client and his users want to do. From that, we can determine what they need. Depending on what you mean by 'the client', all the client side things are fine :) The web front-end I am working on here is for internal use only. To allow non-technical people to set up clients and their apps. The more I look into this, the more I am leaning towards some shell scripts for client management, invoking them by cron. Then if an immediate response is needed someone technical will have to manually run the cron job. It looks like the law of diminishing returns for me to build something really usable. The more I hear, the more confused I get. I still don't understand what your client is going to do? Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Database Administration
On Fri, Sep 24, 2010 at 2:05 PM, tedd wrote: > At 11:19 AM +0100 9/24/10, Tom Barrett wrote: >> >> On 22 September 2010 21:40, Bastien Koert wrote: >> >>> Not at all. What I would suggest is that you create a separate mysql >>> user that is used exclusively by the script to do the create stuff. >>> The regular application user account should not have those privileges >>> at all. >>> >> >> I'm not actually that familiar with DB admin to that extent. I have either >> app users with lock+crud on specific databases, or root. As a an aside, >> would you know if there is a level of permissions for a user between app >> and >> root that would be 'sensibly secure' (it will be MySQL 5)? >> >> >>> Another option, if immediate response is not required, is to save this >>> data into the system for a cron script with another user account to >>> run. >>> >> >> This was sort of my first instinct. I ponder writing a small daemon/cron >> that queries a database table (client list) and does all the 'build' bits. >> The main issue with cron is that the users would want a fairly immediate >> response. Seconds is acceptable, but a 5 minute cron might be too slow. >> >> >>> Is there a reason for you not to place all the data in one DB and just >>> separate them out based on user id, to ensure they only see their own >>> data >>> >> >> For legal reasons. Each client must have separate data. I need to be able >> to >> box up all the client data (containing multiple app instances) and be 100% >> sure that I am giving them all their data and nobody else's. >> >> On 23 September 2010 18:04, tedd wrote: >> >>> No, but from what you've said, I don't think the end user must have >>> privileges and the ability to create a database and tables. It sounds >>> more >>> like allowing the user to set up his own admin for acceptable users -- >>> there's a big difference. >>> >>> So, what you need to define is what the client and his users want to do. >>> From that, we can determine what they need. >> >> >> Depending on what you mean by 'the client', all the client side things are >> fine :) >> The web front-end I am working on here is for internal use only. To allow >> non-technical people to set up clients and their apps. >> >> The more I look into this, the more I am leaning towards some shell >> scripts >> for client management, invoking them by cron. Then if an immediate >> response >> is needed someone technical will have to manually run the cron job. It >> looks >> like the law of diminishing returns for me to build something really >> usable. > > The more I hear, the more confused I get. > > I still don't understand what your client is going to do? > > Cheers, > > tedd > > -- > --- > http://sperling.com/ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > @tedd, He wants not techie users to create new systems for their clients when they sign up. It involves creating a DB and he's wondering about security for that. The main part of the app needs the least priv's to run (select, update, insert [,delete]) while the creating the DB obviously takes more. The OP was asking how to best handle that since the he didn't want to give the main app DB user account more privs than needed. -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if/elseif being treated as if/if
At 1:50 PM -0400 9/24/10, Andy McKenzie wrote: Hey folks, Here's the deal. I have the following code: if($col_vals[$i][$val['column']] == $search_result[0][$col]) { echo ' selected="selected"'; } elseif($val['default'] == $col_vals[$i][$val['column']]) { echo ' selected="selected"'; } It's supposed to check whether there's a value in the db ($search_result[0][$col]) that matches the current column value, and if not, check whether the default matches it. It does that, sort of. In fact, both statements trigger, which I would have said wasn't possible. So the question is: what causes both parts of an if/elseif statement to trigger? As far as I can see my punctuation is correct, and I've confirmed through debugging statements that all the values are what I expect, so how do I make the elseif stop acting like another if? Or, alternatively, have I just misunderstood all this time what the if/elseif statement does? Thanks, Alex Alex: I am not in the majority when I say for conditions where you have more than two options use a switch control and not an elseif. In 40+ years of programming, I have never used elseif because the control confuses me. It is *much* easier for me to use, understand, and document a switch statement than an elseif. Your mileage may vary. Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] if/elseif being treated as if/if
From: tedd > At 1:50 PM -0400 9/24/10, Andy McKenzie wrote: >>Hey folks, >> >> Here's the deal. I have the following code: >> >>if($col_vals[$i][$val['column']] == $search_result[0][$col]) >> { echo ' selected="selected"'; } >>elseif($val['default'] == $col_vals[$i][$val['column']]) >> { echo ' selected="selected"'; } >> >> It's supposed to check whether there's a value in the db >>($search_result[0][$col]) that matches the current column value, and >>if not, check whether the default matches it. It does that, sort of. >>In fact, both statements trigger, which I would have said wasn't >>possible. >> >> So the question is: what causes both parts of an if/elseif >>statement to trigger? As far as I can see my punctuation is correct, >>and I've confirmed through debugging statements that all the values >>are what I expect, so how do I make the elseif stop acting like >>another if? Or, alternatively, have I just misunderstood all this >>time what the if/elseif statement does? > > Alex: > > I am not in the majority when I say for conditions where you have > more than two options use a switch control and not an elseif. > > In 40+ years of programming, I have never used elseif because the > control confuses me. It is *much* easier for me to use, understand, > and document a switch statement than an elseif. > > Your mileage may vary. A switch works when a single test can dispatch all possible branches. If you have a series of tests where each looks for a different subset of conditions, you need an elseif. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] if/elseif being treated as if/if
I found the problem while I was copying the code over. The problem is that the if triggers in loop one, and the elseif triggers in loop two. In other words, it does exactly what it's supposed to, I just didn't think through what the loop would accomplish. Now to figure out how to make it do what I meant it to do. For the benefit of people who screwed up the same way I did: while($i < count($col_vals)) { # Start populating drop box $temp_column = $val['column']; echo '' . $col_vals[$i][$val['column']] . '' . "\n"; $i++; } # End populating drop box And here's the output: vlan1201 none vlan1288 While generating line one of the output: $col_vals[$i][$val['column']] = 'vlan1201' $search_result[0][$col] = 'vlan1201' $val['default'] = 'none' Naturally, in round one, it's selected -- that's the if statement. In round two, it's also selected -- that's the elseif statement. In round three, neither applies. To fix it, I changed the elseif to be as follows: elseif(($val['default'] == $col_vals[$i][$val['column']]) && (!isset($search_result[0][$col]))) Now the elseif only triggers if there is a default, but there is no value in the DB for that field. Hope my failure to think saves someone else some trouble later! -Alex On Fri, Sep 24, 2010 at 1:56 PM, chris h wrote: > Andy I see no reason why both echo's would fire; unless this block of code > gets executed multiple times. can we see more of the code? > > Chris H. > > > On Fri, Sep 24, 2010 at 1:50 PM, Andy McKenzie wrote: >> >> Hey folks, >> >> Here's the deal. I have the following code: >> >> if($col_vals[$i][$val['column']] == $search_result[0][$col]) >> { echo ' selected="selected"'; } >> elseif($val['default'] == $col_vals[$i][$val['column']]) >> { echo ' selected="selected"'; } >> >> It's supposed to check whether there's a value in the db >> ($search_result[0][$col]) that matches the current column value, and >> if not, check whether the default matches it. It does that, sort of. >> In fact, both statements trigger, which I would have said wasn't >> possible. >> >> So the question is: what causes both parts of an if/elseif >> statement to trigger? As far as I can see my punctuation is correct, >> and I've confirmed through debugging statements that all the values >> are what I expect, so how do I make the elseif stop acting like >> another if? Or, alternatively, have I just misunderstood all this >> time what the if/elseif statement does? >> >> Thanks, >> Alex >> >> -- >> 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] if/elseif being treated as if/if
[snip] I am not in the majority when I say for conditions where you have more than two options use a switch control and not an elseif. In 40+ years of programming, I have never used elseif because the control confuses me. It is *much* easier for me to use, understand, and document a switch statement than an elseif. [/snip] I second this, but first I must ask; have you echo'd out the values of each item to confirm what you are evaluating? Don't get me wrong, using elseif is a fine control structure if it sees limited use, like this; if('foo' == $a){ // do foo } elseif('bar' == $a){ // do bar } else { // do glorp } If it goes beyond that I use a switch control and it has served me well for years. My bet is if you echo out the values of the items you're evaluating you will see something that will point you to the cause of your issues. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Database Administration
At 2:09 PM -0400 9/24/10, Bastien Koert wrote: @tedd, He wants not techie users to create new systems for their clients when they sign up. It involves creating a DB and he's wondering about security for that. The main part of the app needs the least priv's to run (select, update, insert [,delete]) while the creating the DB obviously takes more. The OP was asking how to best handle that since the he didn't want to give the main app DB user account more privs than needed. Okay, what does creating "new systems for their clients" mean? What I want to know is specifically what these non-techie users intend to do? Please don't answer that they want to set up accounts for their clients because that is meaningless to me. That could mean anything. So, what specifically are these non-techie users going to do? Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Database Administration
On Fri, Sep 24, 2010 at 2:26 PM, tedd wrote: > At 2:09 PM -0400 9/24/10, Bastien Koert wrote: >> >> @tedd, >> >> He wants not techie users to create new systems for their clients when >> they sign up. It involves creating a DB and he's wondering about >> security for that. The main part of the app needs the least priv's to >> run (select, update, insert [,delete]) while the creating the DB >> obviously takes more. The OP was asking how to best handle that since >> the he didn't want to give the main app DB user account more privs >> than needed. > > Okay, what does creating "new systems for their clients" mean? > > What I want to know is specifically what these non-techie users intend to > do? > > Please don't answer that they want to set up accounts for their clients > because that is meaningless to me. That could mean anything. > > So, what specifically are these non-techie users going to do? > > Cheers, > > tedd > > > -- > --- > http://sperling.com/ > Create a DB schema, create and populate tables. -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] if/elseif being treated as if/if
At 2:23 PM -0400 9/24/10, Bob McConnell wrote: A switch works when a single test can dispatch all possible branches. If you have a series of tests where each looks for a different subset of conditions, you need an elseif. Bob McConnell Bob: Not so, O'wise one. This will work: switch(1) { case $a > $b: /* whatever break; case $c == 1: /* whatever break; case $d == 'this works': /* whatever break; } Granted, it's not the normal way a switch works in some other languages, but it does work in PHP. :-) Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Database Administration
At 2:36 PM -0400 9/24/10, Bastien Koert wrote: On Fri, Sep 24, 2010 at 2:26 PM, tedd wrote: At 2:09 PM -0400 9/24/10, Bastien Koert wrote: @tedd, He wants not techie users to create new systems for their clients when they sign up. It involves creating a DB and he's wondering about security for that. The main part of the app needs the least priv's to run (select, update, insert [,delete]) while the creating the DB obviously takes more. The OP was asking how to best handle that since the he didn't want to give the main app DB user account more privs than needed. Okay, what does creating "new systems for their clients" mean? What I want to know is specifically what these non-techie users intend to do? Please don't answer that they want to set up accounts for their clients because that is meaningless to me. That could mean anything. > So, what specifically are these non-techie users going to do? Create a DB schema, create and populate tables. Creating a DB schema is not for non-techies -- you really need to know what you are doing to do this. But we all live with what we create. Cheers, tedd -- --- http://sperling.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] if/elseif being treated as if/if
this would be the same as: (commented below) On Fri, 2010-09-24 at 15:30 -0400, tedd wrote: > At 2:23 PM -0400 9/24/10, Bob McConnell wrote: > > > >A switch works when a single test can dispatch all possible branches. If > >you have a series of tests where each looks for a different subset of > >conditions, you need an elseif. > > > >Bob McConnell > > Bob: > > Not so, O'wise one. > > This will work: > > switch(1) > { > case $a > $b: if($a > $b) > /* whatever > break; > elseif ($c == 1) > case $c == 1: > /* whatever > break; > elseif($d == 'this works') > case $d == 'this works': > /* whatever > break; > } > Granted, it's not the normal way a switch works in some other > languages, but it does work in PHP. :-) > All you have to remember, and same as with this switch, is that the first match, will stop processing the rest of the stuff. Steve. > Cheers, > > tedd > > -- > --- > http://sperling.com/ > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Database Administration
From: tedd >At 2:36 PM -0400 9/24/10, Bastien Koert wrote: >>On Fri, Sep 24, 2010 at 2:26 PM, tedd wrote: >>> At 2:09 PM -0400 9/24/10, Bastien Koert wrote: @tedd, He wants not techie users to create new systems for their clients when they sign up. It involves creating a DB and he's wondering about security for that. The main part of the app needs the least priv's to run (select, update, insert [,delete]) while the creating the DB obviously takes more. The OP was asking how to best handle that since the he didn't want to give the main app DB user account more privs than needed. >>> >>> Okay, what does creating "new systems for their clients" mean? >>> >>> What I want to know is specifically what these non-techie users intend to >>> do? >>> >>> Please don't answer that they want to set up accounts for their clients >>> because that is meaningless to me. That could mean anything. >>> >> > So, what specifically are these non-techie users going to do? >> >>Create a DB schema, create and populate tables. > > Creating a DB schema is not for non-techies -- you really need to > know what you are doing to do this. > > But we all live with what we create. I suspect he actually means create a new table using a predefined schema. But unfortunately, he doesn't appear to know enough about the problem to be able to explain it. He is either in way over his depth, or hasn't done a very good job of defining his requirements. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] if/elseif being treated as if/if
From: tedd > At 2:23 PM -0400 9/24/10, Bob McConnell wrote: >> >>A switch works when a single test can dispatch all possible branches. If >>you have a series of tests where each looks for a different subset of >>conditions, you need an elseif. > Not so, O'wise one. > > This will work: > > switch(1) > { > case $a > $b: > /* whatever > break; > > case $c == 1: > /* whatever > break; > > case $d == 'this works': > /* whatever > break; > } > > Granted, it's not the normal way a switch works in some other > languages, but it does work in PHP. :-) That is just so wrong, it can't actually be taken seriously. There is simply no justification for such broken logic. Bob McConnell -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Database Administration
On Fri, Sep 24, 2010 at 3:50 PM, Bob McConnell wrote: > From: tedd > >>At 2:36 PM -0400 9/24/10, Bastien Koert wrote: >>>On Fri, Sep 24, 2010 at 2:26 PM, tedd wrote: At 2:09 PM -0400 9/24/10, Bastien Koert wrote: > > �...@tedd, > > He wants not techie users to create new systems for their clients > when > they sign up. It involves creating a DB and he's wondering about > security for that. The main part of the app needs the least priv's > to > run (select, update, insert [,delete]) while the creating the DB > obviously takes more. The OP was asking how to best handle that > since > the he didn't want to give the main app DB user account more privs > than needed. Okay, what does creating "new systems for their clients" mean? What I want to know is specifically what these non-techie users > intend to do? Please don't answer that they want to set up accounts for their > clients because that is meaningless to me. That could mean anything. >>> > So, what specifically are these non-techie users going to do? >>> >>>Create a DB schema, create and populate tables. >> >> Creating a DB schema is not for non-techies -- you really need to >> know what you are doing to do this. >> >> But we all live with what we create. > > I suspect he actually means create a new table using a predefined > schema. But unfortunately, he doesn't appear to know enough about the > problem to be able to explain it. He is either in way over his depth, or > hasn't done a very good job of defining his requirements. > > Bob McConnell > The OP mentioned that each new client needed their own DB so that is how I took it. Having exactly the exact same tables in the structure with different names is just bad practice to. That just screams creating a multi-tenant DB. At work we do create each DB as a clone of a master table, but it is done manually and thankfully not that often. -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] if/elseif being treated as if/if
On Fri, 2010-09-24 at 15:44 -0400, Steve Staples wrote: > this would be the same as: > (commented below) > > On Fri, 2010-09-24 at 15:30 -0400, tedd wrote: > > At 2:23 PM -0400 9/24/10, Bob McConnell wrote: > > > > > >A switch works when a single test can dispatch all possible branches. If > > >you have a series of tests where each looks for a different subset of > > >conditions, you need an elseif. > > > > > >Bob McConnell > > > > Bob: > > > > Not so, O'wise one. > > > > This will work: > > > > switch(1) > > { > > case $a > $b: > if($a > $b) > > /* whatever > > break; > > > elseif ($c == 1) > > case $c == 1: > > /* whatever > > break; > > > elseif($d == 'this works') > > case $d == 'this works': > > /* whatever > > break; > > } > > Granted, it's not the normal way a switch works in some other > > languages, but it does work in PHP. :-) > > > > All you have to remember, and same as with this switch, is that the > first match, will stop processing the rest of the stuff. > > Steve. > > > > > > Cheers, > > > > tedd > > > > -- > > --- > > http://sperling.com/ > > > > > Actually, processing only stops at the first break statement, so in this example, it would run through to case 3: $var = 1; switch($var) { case 1: { echo 1; } case 2: { echo 2; } case 3: { echo 3; break; } case 4: { echo 4; break; } default: { echo 'default'; } } This would display '123' in the output. Thanks, Ash http://www.ashleysheridan.co.uk
RE: [PHP] if/elseif being treated as if/if
On Fri, 2010-09-24 at 15:54 -0400, Bob McConnell wrote: > From: tedd > > > At 2:23 PM -0400 9/24/10, Bob McConnell wrote: > >> > >>A switch works when a single test can dispatch all possible branches. > If > >>you have a series of tests where each looks for a different subset of > >>conditions, you need an elseif. > > > Not so, O'wise one. > > > > This will work: > > > > switch(1) > > { > > case $a > $b: > > /* whatever > > break; > > > > case $c == 1: > > /* whatever > > break; > > > > case $d == 'this works': > > /* whatever > > break; > > } > > > > Granted, it's not the normal way a switch works in some other > > languages, but it does work in PHP. :-) > > That is just so wrong, it can't actually be taken seriously. There is > simply no justification for such broken logic. > > Bob McConnell > I don't often use this type of logic, but I have used it before and it's served me well. Essentially, a switch is a glorified if statement, and I find them a lot nicer to read and write than a series of if/elseif blocks. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] if/elseif being treated as if/if
On Fri, 2010-09-24 at 16:08 -0400, Joshua Kehn wrote: > On Sep 24, 2010, at 4:04 PM, Ashley Sheridan wrote: > > > On Fri, 2010-09-24 at 15:54 -0400, Bob McConnell wrote: > > > >> From: tedd > >> > >>> At 2:23 PM -0400 9/24/10, Bob McConnell wrote: > > A switch works when a single test can dispatch all possible branches. > >> If > you have a series of tests where each looks for a different subset of > conditions, you need an elseif. > >> > >>> Not so, O'wise one. > >>> > >>> This will work: > >>> > >>> switch(1) > >>>{ > >>>case $a > $b: > >>>/* whatever > >>>break; > >>> > >>>case $c == 1: > >>>/* whatever > >>>break; > >>> > >>>case $d == 'this works': > >>>/* whatever > >>>break; > >>>} > >>> > >>> Granted, it's not the normal way a switch works in some other > >>> languages, but it does work in PHP. :-) > >> > >> That is just so wrong, it can't actually be taken seriously. There is > >> simply no justification for such broken logic. > >> > >> Bob McConnell > >> > > > > > > I don't often use this type of logic, but I have used it before and it's > > served me well. Essentially, a switch is a glorified if statement, and I > > find them a lot nicer to read and write than a series of if/elseif > > blocks. > > > > > > Thanks, > > Ash > > http://www.ashleysheridan.co.uk > > > > > > Proper bracing style makes everything visually appealing. > > if(cond) > { > /* perform */ > } > else if(cond) > { > /* action */ > } > else if(cond) > { > /* if */ > } > else > { > /* applicable to cond */ > } > > Rather then > > if(cond){ > > } else if(cond) { > > } else if(cond) { > > } else { > > } > > which may look condensed but to me doesn't follow the program flow at all. > > Regards, > > -Josh That is my preferred way of coding anyway for several reasons as you can do this without causing any problems: //if(condition) { // code here } whereas if you do it with the variant of this style: // if(condition) { // code here //} You have to comment out two lines instead of one to achieve the same result, and you only save a byte (or two if the line ending is a carriage return and a line break) by putting the opening brace on the first line. The style made sense when it was used for code printouts and displaying on a text terminal, but in these modern days of GUI editors and the (mostly conceptual) paperless office, there seems little point. That is all a little off-topic though. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] Re: Copying an Object
> > On 9/24/2010 4:09 AM, Gary wrote: >> Daniel Kolbo wrote: >> >>> Say you have two classes: human and male. Further, say male extends >>> human. Let's say you have a human object. Then later you want to make >>> that human object a male object. This seems to be a pretty reasonable >>> thing to request of our objects. >> >> I don't think any human can change gender without major surgery, but I >> don't know if you just chose your example badly or whether you really >> think objects should be able to mutate into other types of object >> without some kind of special treatment. >> >>> This type of thing would especially be >>> easy if objects of parent classes could be cast as an object of its >>> extended class. >> >> Where would the extra data come from to fill in any fields the base >> class does not have? Just think of a simple example with a Shape class, >> extended by a ColouredShape class which contains some data about the >> object's colour - if you have a Shape object it can't become a >> ColouredShape without some surgery because bits of the ColouredShape's >> anatomy are not present. >> >> -- >> GaryPlease do NOT send me 'courtesy' replies off-list. >> PHP 5.2.12 (cli) (built: Jan 14 2010 14:54:11) >> 1.7.7(0.230/5/3) 2010-08-31 09:58 Cygwin >> >> > > The colouredShape class would probably have a member variable called > $color. This member could have a default value (as defined in the > class), be defined through the __construct() method (which would be > invoked upon such a cast procedure...perhaps there could be a __cast() > method much like how there is a __clone() method. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Copying an Object
On 9/24/2010 6:11 PM, Daniel Kolbo wrote: > On 9/24/2010 8:35 AM, Peter Lind wrote: >> On 24 September 2010 14:22, Bob McConnell wrote: >>> From: David Hutto >>> On Fri, Sep 24, 2010 at 4:09 AM, Gary wrote: > Daniel Kolbo wrote: > >> Say you have two classes: human and male. Further, say male extends >> human. Let's say you have a human object. Then later you want to make >> that human object a male object. This seems to be a pretty reasonable >> thing to request of our objects. > > I don't think any human can change gender without major surgery, but I > don't know if you just chose your example badly or whether you really > think objects should be able to mutate into other types of object > without some kind of special treatment. But it would work in something like makehuman, where you start with a neuter form and scale one way or the other for physical features. If I remember correctly, we're' all xx until you become xy(genetically speaking). >>> >>> This is one of the details that really bothers me about OOP. It makes it >>> impossible to implement some very reasonable scenarios. 80% of the time, >>> when a patron is added to a system, we don't know which gender they are. >>> More than 50% of the time, we will never know, since the client doesn't >>> keep track of it. But the rest of them will be assigned sometime after they >>> were added. i.e. the gender assignment comes from a secondary source that >>> is not available at the time the patron is entered. >>> >> >> If you can't handle that, it's not the fault of OOP but your lack of >> programming skills in OOP I'd say (and I mean no disrespect there, I'm >> just pretty sure your scenario can be handled very easily in OOP). >> >> And no, I have no urge to defend OOP in PHP, I just see this entire >> thread as a complete non-starter: if the language doesn't let you do >> something in a particular way, how about you stop, take a breather, >> then ask if perhaps there's a better way in the language to do what >> you want done? That would normally be a much more productive and >> intelligent response than either a) pressing on in the face of failure >> or b) complaining about your specific needs and how the language fails >> to meet them. >> >> Regards >> Peter >> > > I would consider the post to be a discussion among the community to > discuss possible improvements for php, to help progress the language to > handle the situations faced by the users of the language, and hey maybe > learn something along the way. I certainly wouldn't consider the post > to be an avenue to belittle members of the community. For some it's > half empty, for others half full. > ` -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Copying an Object
On 25 September 2010 00:11, Daniel Kolbo wrote: > On 9/24/2010 8:35 AM, Peter Lind wrote: >> On 24 September 2010 14:22, Bob McConnell wrote: >>> From: David Hutto >>> On Fri, Sep 24, 2010 at 4:09 AM, Gary wrote: > Daniel Kolbo wrote: > >> Say you have two classes: human and male. Further, say male extends >> human. Let's say you have a human object. Then later you want to make >> that human object a male object. This seems to be a pretty reasonable >> thing to request of our objects. > > I don't think any human can change gender without major surgery, but I > don't know if you just chose your example badly or whether you really > think objects should be able to mutate into other types of object > without some kind of special treatment. But it would work in something like makehuman, where you start with a neuter form and scale one way or the other for physical features. If I remember correctly, we're' all xx until you become xy(genetically speaking). >>> >>> This is one of the details that really bothers me about OOP. It makes it >>> impossible to implement some very reasonable scenarios. 80% of the time, >>> when a patron is added to a system, we don't know which gender they are. >>> More than 50% of the time, we will never know, since the client doesn't >>> keep track of it. But the rest of them will be assigned sometime after they >>> were added. i.e. the gender assignment comes from a secondary source that >>> is not available at the time the patron is entered. >>> >> >> If you can't handle that, it's not the fault of OOP but your lack of >> programming skills in OOP I'd say (and I mean no disrespect there, I'm >> just pretty sure your scenario can be handled very easily in OOP). >> >> And no, I have no urge to defend OOP in PHP, I just see this entire >> thread as a complete non-starter: if the language doesn't let you do >> something in a particular way, how about you stop, take a breather, >> then ask if perhaps there's a better way in the language to do what >> you want done? That would normally be a much more productive and >> intelligent response than either a) pressing on in the face of failure >> or b) complaining about your specific needs and how the language fails >> to meet them. >> >> Regards >> Peter >> > > I would consider the post to be a discussion among the community to > discuss possible improvements for php, to help progress the language to > handle the situations faced by the users of the language, and hey maybe > learn something along the way. I certainly wouldn't consider the post > to be an avenue to belittle members of the community. For some it's > half empty, for others half full. > ` I apologize for the wording of my post - I did not intend to belittle anyone. Your posts seem to me, however, rather typical: "I am coming up against this problem, why doesn't the language let me solve it the way I want it to?" - something this last response also suggests ("I would consider the post to be a discussion among the community to discuss possible improvements for php"). Many people have already pointed out that there's likely a much better solution to the problem at hand, yet you still insist that the language should be improved (the latest idea being a __cast() function) - and I cannot see you once commenting on the composition strategy. Was the "... and hey maybe learn something along the way." meant only for others? Anyway, seeing as my glass is half-empty and I'm not adding anything constructive to thread I'll refrain from posting more. Regards Peter -- WWW: http://plphp.dk / http://plind.dk LinkedIn: http://www.linkedin.com/in/plind BeWelcome/Couchsurfing: Fake51 Twitter: http://twitter.com/kafe15 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php