Re: [PHP] Static methods vs. plain functions
2013/9/19 Simon Dániel simondan...@gmail.com Hi, I am working on an OOP project, and cannot decide which way to follow when I have to write a simple function. For example, I want to write a function which generates a random string. In an OOP environtment, it is a matter of course to create a static class and a static method for that. But why? Isn't it more elegant, if I implement such a simple thing as a plain function? I'd say: Definitely! Not to mention that a function is more efficient than a class method. Actually I wouldn't be so sure about that. So, in object-oriented programming, what is the best practice to implement such a simple function? In strict-OOP [1] you would choose a static method, because functions are simply forbidden. However, PHP isn't strict about that by itself. So I for myself don't like the dogmatic We use classes and nothing else!-approach. If a function fits better, it's OK to be a function. [1] Actually that would end up in a mix of OOP and class-oriented programming, which isn't that strict. -- github.com/KingCrunch
Re: [PHP] Static methods vs. plain functions
2013/9/19 Aziz Saleh azizsa...@gmail.com I think that it would be more elegant if you are already in a OOP to keep the flow and stick to OOP. It just doesn't make sense to me in an environment that uses OOP to have functions laying around. buzzword: multi-paradigm. Thats why it could make sense ;) Personally I like to group similar functionality together in their own objects, - That aren't objects, but classes. Actually you don't programm in object-oriented, but in class-oriented (or probably a mix) - You can (imo should) use namespaces this way I can reuse them on different projects, the random string generator is an excellent example of something I usually use in almost all of my projects. Function calling is usually faster than object calling (depends on how you benchmark it) since there is an overhead to it. There are some who tried to benchmark this and had opposite results, It all comes down to how are you going to use that functionality: http://www.webhostingtalk.com/showthread.php?t=538076 http://www.micro-optimization.com/global-function-vs-static-method Personally in my projects - specifically if I use a framework, I try to stay away from making standalone functions unless absolutely necessary. On Thu, Sep 19, 2013 at 12:44 PM, Sebastian Krebs krebs@gmail.comwrote: 2013/9/19 Simon Dániel simondan...@gmail.com Hi, I am working on an OOP project, and cannot decide which way to follow when I have to write a simple function. For example, I want to write a function which generates a random string. In an OOP environtment, it is a matter of course to create a static class and a static method for that. But why? Isn't it more elegant, if I implement such a simple thing as a plain function? I'd say: Definitely! Not to mention that a function is more efficient than a class method. Actually I wouldn't be so sure about that. So, in object-oriented programming, what is the best practice to implement such a simple function? In strict-OOP [1] you would choose a static method, because functions are simply forbidden. However, PHP isn't strict about that by itself. So I for myself don't like the dogmatic We use classes and nothing else!-approach. If a function fits better, it's OK to be a function. [1] Actually that would end up in a mix of OOP and class-oriented programming, which isn't that strict. -- github.com/KingCrunch -- github.com/KingCrunch
Re: [PHP] high traffic websites
2013/9/18 Negin Nickparsa nickpa...@gmail.com In general, what are the best ways to handle high traffic websites? VPS(clouds)? web analyzers? dedicated servers? distributed memory cache? Yes :) But seriously: That is a topic most of us spent much time to get into it. You can explain it with a bunch of buzzwords. Additional, how do you define high traffic websites? Do you already _have_ such a site? Or do you _want_ it? It's important, because I've seen it far too often, that projects spent too much effort in their high traffic infrastructure and at the end it wasn't that high traffic ;) I wont say, that you cannot be successfull, but you should start with an effort you can handle. Regards, Sebastian Sincerely Negin Nickparsa -- github.com/KingCrunch
Re: [PHP] high traffic websites
2013/9/18 Negin Nickparsa nickpa...@gmail.com Thank you Camilo to be more in details,suppose the website has 80,000 users and each page takes 200 ms to be rendered and you have thousand hits in a second so we want to reduce the time of rendering. is there any way to reduce the rendering time? Read about frontend-/proxy-caching (Nginx, Varnish) and ESI/SSI-include (also NGinx and Varnish ;)). The idea is simply If you don't have to process on every request in the backend, don't process it in the backend on every request. But maybe you mixed up some words, because the rendering time is the time consumed by the renderer within the browser (HTML and CSS). This you can improve, if you improve your HTML/CSS :) I am a little bit curious: Do you _really_ have 1000 requests/second, or do you just throw some numbers in? ;) other thing is suppose they want to upload files simultaneously and the videos are in the website not on another server like YouTube and so streams are really consuming the bandwidth. Well, if there are streams, there are streams. I cannot imagine, that there is another way someone can stream a video without downloading it. Also,It is troublesome to get backups,when getting backups you have problem of lock backing up with bulk of data. Even in times, where there is not that much traffix? Automatic backup at 3:00 in the morning for example? Sincerely Negin Nickparsa On Wed, Sep 18, 2013 at 12:50 PM, Camilo Sperberg unrea...@gmail.comwrote: On Sep 18, 2013, at 09:38, Negin Nickparsa nickpa...@gmail.com wrote: Thank you Sebastian..actually I will already have one if qualified for the job. Yes, and I may fail to handle it that's why I asked for guidance. I wanted some tidbits to start over. I have searched through yslow, HTTtrack and others. I have searched through php list in my email too before asking this question. it is kind of beneficial for all people and not has been asked directly. Sincerely Negin Nickparsa On Wed, Sep 18, 2013 at 10:45 AM, Sebastian Krebs krebs@gmail.com wrote: 2013/9/18 Negin Nickparsa nickpa...@gmail.com In general, what are the best ways to handle high traffic websites? VPS(clouds)? web analyzers? dedicated servers? distributed memory cache? Yes :) But seriously: That is a topic most of us spent much time to get into it. You can explain it with a bunch of buzzwords. Additional, how do you define high traffic websites? Do you already _have_ such a site? Or do you _want_ it? It's important, because I've seen it far too often, that projects spent too much effort in their high traffic infrastructure and at the end it wasn't that high traffic ;) I wont say, that you cannot be successfull, but you should start with an effort you can handle. Regards, Sebastian Sincerely Negin Nickparsa -- github.com/KingCrunch Your question is way too vague to be answered properly... My best guess would be that it depends severely on the type of website you have and how's the current implementation being well... implemented. Simply said: what works for Facebook may/will not work for linkedIn, twitter or Google, mainly because the type of search differs A LOT: facebook is about relations between people, twitter is about small pieces of data not mainly interconnected between each other, while Google is all about links and all type of content: from little pieces of information through whole Wikipedia. You could start by studying how varnish and redis/memcached works, you could study about how proxies work (nginx et al), CDNs and that kind of stuff, but if you want more specific answers, you could better ask specific question. In the PHP area, an opcode cache does the job very well and can accelerate the page load by several orders of magnitude, I recommend OPCache, which is already included in PHP 5.5. Greetings. -- github.com/KingCrunch
Re: [PHP] high traffic websites
2013/9/18 Camilo Sperberg unrea...@gmail.com On Sep 18, 2013, at 14:26, Haluk Karamete halukkaram...@gmail.com wrote: I recommend OPCache, which is already included in PHP 5.5. Camilo, I'm just curious about the disadvantageous aspects of OPcache. My logic says there must be some issues with it otherwise it would have come already enabled. Sent from iPhone On Sep 18, 2013, at 2:20 AM, Camilo Sperberg unrea...@gmail.com wrote: On Sep 18, 2013, at 09:38, Negin Nickparsa nickpa...@gmail.com wrote: Thank you Sebastian..actually I will already have one if qualified for the job. Yes, and I may fail to handle it that's why I asked for guidance. I wanted some tidbits to start over. I have searched through yslow, HTTtrack and others. I have searched through php list in my email too before asking this question. it is kind of beneficial for all people and not has been asked directly. Sincerely Negin Nickparsa On Wed, Sep 18, 2013 at 10:45 AM, Sebastian Krebs krebs@gmail.com wrote: 2013/9/18 Negin Nickparsa nickpa...@gmail.com In general, what are the best ways to handle high traffic websites? VPS(clouds)? web analyzers? dedicated servers? distributed memory cache? Yes :) But seriously: That is a topic most of us spent much time to get into it. You can explain it with a bunch of buzzwords. Additional, how do you define high traffic websites? Do you already _have_ such a site? Or do you _want_ it? It's important, because I've seen it far too often, that projects spent too much effort in their high traffic infrastructure and at the end it wasn't that high traffic ;) I wont say, that you cannot be successfull, but you should start with an effort you can handle. Regards, Sebastian Sincerely Negin Nickparsa -- github.com/KingCrunch Your question is way too vague to be answered properly... My best guess would be that it depends severely on the type of website you have and how's the current implementation being well... implemented. Simply said: what works for Facebook may/will not work for linkedIn, twitter or Google, mainly because the type of search differs A LOT: facebook is about relations between people, twitter is about small pieces of data not mainly interconnected between each other, while Google is all about links and all type of content: from little pieces of information through whole Wikipedia. You could start by studying how varnish and redis/memcached works, you could study about how proxies work (nginx et al), CDNs and that kind of stuff, but if you want more specific answers, you could better ask specific question. In the PHP area, an opcode cache does the job very well and can accelerate the page load by several orders of magnitude, I recommend OPCache, which is already included in PHP 5.5. Greetings. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The original RFC states: https://wiki.php.net/rfc/optimizerplus The integration proposed for PHP 5.5.0 is mostly 'soft' integration. That means that there'll be no tight coupling between Optimizer+ and PHP; Those who wish to use another opcode cache will be able to do so, by not loading Optimizer+ and loading another opcode cache instead. As per the Suggested Roadmap above, we might want to review this decision in the future; There might be room for further performance or functionality gains from tighter integration; None are known at this point, and they're beyond the scope of this RFC. So that's why OPCache isn't enabled by default in PHP 5.5 Also worth to mention, that it is the first release with an opcode-cache integrated. Giving the other some release to get used to it, sounds useful :) Greetings. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Resolving a PHP Notice Error
2013/9/17 Ron Piggott ron.pigg...@actsministries.org I am wanting to establish a default sort by preference when the user hasn’t specified one. I setup to test this with: ?php if ( !is_set( $sort_by_preference ) ) { $sort_by_preference = government_wording; } ? But I am receiving a Notice error: Notice: Undefined variable: sort_by_preference in GIFI_codes.php on line 11- Line 11 is “if ( !is_set( $sort_by_preference ) ) {“What is the correct way to test this without triggering a Notice error?Ron Ron Piggott Because actually you are looking for isset() (not is_set()). www.TheVerseOfTheDay.info -- github.com/KingCrunch
Re: [PHP] PHP Dependency Injector
Sorry guys if disturbed. 2013/9/5 Bastien Koert phps...@gmail.com Jee, that should have been a friday comment...how does your dic standout On Thu, Sep 5, 2013 at 4:06 PM, Sorin Badea sorin.bade...@gmail.comwrote: There are few tutorials about home made dic. How does your dic stand out from the crowd ? Regards. On Thu, Sep 5, 2013 at 10:56 PM, Juan Sebastian Scatularo sebastianscatul...@gmail.com wrote: Hello people, I want to share with you a simple and small Dependency Injector made for me. https://github.com/abloos/Sofia Regards -- Facebook: www.facebook.com/JuanSebastianScatularo Twitter: www.twitter.com/js_scatularo Web: www.sebastianscatularo.com.ar -- Sorin Badea - Software Engineer -- Bastien Cat, the other other white meat -- Facebook: www.facebook.com/JuanSebastianScatularo Twitter: www.twitter.com/js_scatularo Web: www.sebastianscatularo.com.ar
Re: [PHP] PHP Dependency Injector
Thanks Sorin, I will do that and I will have more care the next time. Regards 2013/9/5 Sorin Badea sorin.bade...@gmail.com Juan, the problem with this list is that that there are too damn many dumb questions. You did something nice but it doesn't stand out. You can check Symfony2 DiC. You can use it as a stand alone component. On Thu, Sep 5, 2013 at 11:30 PM, Juan Sebastian Scatularo sebastianscatul...@gmail.com wrote: Sorry guys if disturbed. 2013/9/5 Bastien Koert phps...@gmail.com Jee, that should have been a friday comment...how does your dic standout On Thu, Sep 5, 2013 at 4:06 PM, Sorin Badea sorin.bade...@gmail.comwrote: There are few tutorials about home made dic. How does your dic stand out from the crowd ? Regards. On Thu, Sep 5, 2013 at 10:56 PM, Juan Sebastian Scatularo sebastianscatul...@gmail.com wrote: Hello people, I want to share with you a simple and small Dependency Injector made for me. https://github.com/abloos/Sofia Regards -- Facebook: www.facebook.com/JuanSebastianScatularo Twitter: www.twitter.com/js_scatularo Web: www.sebastianscatularo.com.ar -- Sorin Badea - Software Engineer -- Bastien Cat, the other other white meat -- Facebook: www.facebook.com/JuanSebastianScatularo Twitter: www.twitter.com/js_scatularo Web: www.sebastianscatularo.com.ar -- Sorin Badea - Software Engineer -- Facebook: www.facebook.com/JuanSebastianScatularo Twitter: www.twitter.com/js_scatularo Web: www.sebastianscatularo.com.ar
[PHP] PHP Dependency Injector
Hello people, I want to share with you a simple and small Dependency Injector made for me. https://github.com/abloos/Sofia Regards -- Facebook: www.facebook.com/JuanSebastianScatularo Twitter: www.twitter.com/js_scatularo Web: www.sebastianscatularo.com.ar
Re: [PHP] Alternate list for eclipse ide support?
2013/8/24 Lester Caine les...@lsces.co.uk With composer being pushed as the 'in way to go' and not being able to see how to get some code relating to bootstrap and smarty development because the links only show composer I've downloaded a plug-in for eclipse that is supposed to handle that. But it's not working as I expect, and while heading over to the plug-ins developers is the obvious step, what I'd actually prefer is a more general PHP/Eclipse list to discuss general IDE problems rather than even PDT biased discussions. Is there a suitable list? And if not is there any interest in setting one up? ... at the risk of proliferating even more lists ... Hi, I for myself switched over to PhpStorm from Eclipse/PDT and I fear meany hear use either PhpStorm, or Netbeans in the meantime. I'm not saying, that nobody is using Eclipse/PDT anymore, but I fear you wont find much interest here. Regards, Sebastian -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=**contacthttp://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.**ukhttp://rainbowdigitalmedia.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Alternate list for eclipse ide support?
2013/8/24 Lester Caine les...@lsces.co.uk Sebastian Krebs wrote: With composer being pushed as the 'in way to go' and not being able to see how to get some code relating to bootstrap and smarty development because the links only show composer I've downloaded a plug-in for eclipse that is supposed to handle that. But it's not working as I expect, and while heading over to the plug-ins developers is the obvious step, what I'd actually prefer is a more general PHP/Eclipse list to discuss general IDE problems rather than even PDT biased discussions. Is there a suitable list? And if not is there any interest in setting one up? ... at the risk of proliferating even more lists ... I for myself switched over to PhpStorm from Eclipse/PDT and I fear meany hear use either PhpStorm, or Netbeans in the meantime. I'm not saying, that nobody is using Eclipse/PDT anymore, but I fear you wont find much interest here. I'm still on PHPEclipse for PHP. PDT just does not work for me, and neither did Netbeans for some of the other languages I have to live with, which is why PHPStorm is no use either. PHPEclipse is still in development? O_o The last time I noticed it, it looked abandoned. However, if it works for you, there is nothing wrong with it. (Just realized: There are really back in business. Interesting ^^) I need python in addition to C/C++ with document handling, and firebird which don't get any support from either so Eclipse is really my only option. Well, Firebird is quite specific (dont know if its supported bei the IntelliJ-platform), but for Python and C Jetbrains has other IDEs (PyCharm, AppCode) :D Just saying: There _are_ alternatives :) However, my last mail wasn't about telling you, that your IDE is bad. But I have the feeling, that this audience may be simply not interested. Regards, Sebastian -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=**contacthttp://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.**ukhttp://rainbowdigitalmedia.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Re: PHP vs JAVA
2013/8/22 David Harkness davi...@highgearmedia.com On Wed, Aug 21, 2013 at 7:56 PM, Curtis Maurand cur...@maurand.comwrote: Sebastian Krebs wrote: Actually the problem is, that the dot . is already in use. With $foo.bar() you cannot tell, if you want to call the method bar() on the object $foo, or if you want to concatenate the value of $foo to the result of the function bar(). There is no other way around this than a different operator for method calls. I didn't think of that. It seems to me there could be an easier operator than - which sometimes will make me stop and look at what keys I'm trying to hit. Just a thought. I forgot about the concatenation operator which is + in Java/C# The PHP language developers were pretty stuck. Because of automatic string-to-numeric-conversion, they couldn't use + for string concatenation. Sadly, they chose . rather than .. which I believe one or two other languages use. If they had, . would have been available once objects rolled around in PHP 4/5. I suspect they chose - since that's used in C and C++ to dereference a pointer. Actually I think .. is quite error-prone, because it is hard to distinguish from . or _ on the _first_ glance, which makes the get quickly through the code. [1] So . is maybe not the best choice, but also remember when it was introduced: That was decades ago. That time it was (probably ;)) the best choice and nowadays I don't think it is too bad at all, beside that _other_ languages use it for other purposes now ;) [1] Yes, I know, that _ is not an operator, but mixed with strings and variables names it is there ;) Ever tried the jetbrains products? :D (No, they don't pay me) I have not, but it looks interesting. I'll have to try it. Those are very good products which have had a strong following for a decade. The free IDE NetBeans also has quite good support for both Java and PHP, and the latest beta version provides a web project that provides front- and back-end debugging of PHP + JavaScript. You can be stepping through JS code and hit an AJAX call and then seamlessly step through the PHP code that handles it. I use NetBeans for PHP/HTML/JS (though I am evaluating JetBrains' PHPStorm now) and Eclipse for Java. You can't beat Eclipse's refactoring support in a free tool, though I think NetBeans is close to catching up. I would bet IntelliJ IDEA for Java by JetBrains is on par at least. Eclipse' code-completion and debugger never worked for me well (and most of the time: at all). It became slower and less responsive with every release. That was the reason I decided to leave it and I don't regret it :) Peace, David -- github.com/KingCrunch
Re: [PHP] Re: PHP vs JAVA
2013/8/21 georg chambert georg.chamb...@telia.com Hi, my I shake the subject a little; Ive been doing some PHP and found it ok to work with not so much fuss, but that was PHP4, what about PHP5 ? Dont really checked the difference but made a short-scan and found that it had be screwed around with ? Any think, should I change to 5 ? ehm ... serious? http://php.net/eol.php BR georg - Original Message - From: Tim Streater t...@clothears.org.uk To: PHP List phpl...@arashidigital.com; php-general@lists.php.net Sent: Wednesday, August 21, 2013 1:59 PM Subject: [PHP] Re: PHP vs JAVA On 20 Aug 2013 at 23:59, PHP List phpl...@arashidigital.com wrote: While I don't have any references to back it up - my guess would be that Java may be seen as more versatile in general programming terms. A staggering number of enterprise level web applications are built with Java, add to that the possibility of writing Android apps with the same knowledge. To me the salient point is, does java has as extensive a library or set of interfaces to other packages (such as SQLite, mysql, etc)? I would say that, in general, the other teacher is incorrect speaking strictly in terms of web development. PHP has already won that crown many times over. That said, when I was in University, it was difficult to find a programming class that taught anything but Java - and that was 10yrs ago now. I chalked it up to the education bubble not being able to see what the rest of the world is actually doing. Was PHP OOP-capable at the time? Perhaps the edu-bubble was simply looking down its nose at PHP. There being lots of courses proves nothing in and of itself. 20 years ago, there were lots of PC mags you could buy, which caused some folks to say look how much better the PC is supported than other platforms. Truth was, at the time, such support was needed given the mess of 640k limits, DOS, IRQs and the like, most of which issues have ceased to be relevant. Anyway, why should one need a course to learn PHP, assuming you already know other languages. It's simple enough. -- Cheers -- Tim --**--** -- 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 -- github.com/KingCrunch
Re: [PHP] Re: PHP vs JAVA
2013/8/21 Curtis Maurand cur...@maurand.com Sorry in advance for the top post. Use the right tool for the Job. I've use Java, C# and PHP. 1. I hate the Perl-like object calls in PHP. I'd rather use . notation in C# and Java. It saves a lot of wear and tear on my left pinky finger. Actually the problem is, that the dot . is already in use. With $foo.bar() you cannot tell, if you want to call the method bar() on the object $foo, or if you want to concatenate the value of $foo to the result of the function bar(). There is no other way around this than a different operator for method calls. 2. Java and C# are both typed languages. Say what you want, but I have working with a string like 02 and have PHP convert that to an integer. sometimes I want that zero in front. If I want that to be an integer in Java it's int myInteger = Integer.parseInt(02); 3. Java development environments (Eclipses, NetBeans, IBM RAD) are pretty horrible. Visual Studio is hands down a better envrionment, even the older versions of it. I've hooked Visual Studio into SVN in the past and it works well. Ever tried the jetbrains products? :D (No, they don't pay me) 4 PHP development environments are many and varied and all of them suck at web debugging. I've used PHPEdit, Zend, Bluefish, Eclipse and a couple others. Bluefish works better on Linux than it does on Windows. I use PhpStorm and it works quite fine. Use the tool for the job at hand. Just my $0.02 worth. cheers, Curtis Tim Streater wrote: On 20 Aug 2013 at 23:59, PHP List phpl...@arashidigital.com wrote: While I don't have any references to back it up - my guess would be that Java may be seen as more versatile in general programming terms. A staggering number of enterprise level web applications are built with Java, add to that the possibility of writing Android apps with the same knowledge. To me the salient point is, does java has as extensive a library or set of interfaces to other packages (such as SQLite, mysql, etc)? I would say that, in general, the other teacher is incorrect speaking strictly in terms of web development. PHP has already won that crown many times over. That said, when I was in University, it was difficult to find a programming class that taught anything but Java - and that was 10yrs ago now. I chalked it up to the education bubble not being able to see what the rest of the world is actually doing. Was PHP OOP-capable at the time? Perhaps the edu-bubble was simply looking down its nose at PHP. There being lots of courses proves nothing in and of itself. 20 years ago, there were lots of PC mags you could buy, which caused some folks to say look how much better the PC is supported than other platforms. Truth was, at the time, such support was needed given the mess of 640k limits, DOS, IRQs and the like, most of which issues have ceased to be relevant. Anyway, why should one need a course to learn PHP, assuming you already know other languages. It's simple enough. -- Cheers -- Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] PHP vs JAVA
2013/8/20 Tedd Sperling t...@sperling.com On Aug 20, 2013, at 10:04 AM, Ashley Sheridan a...@ashleysheridan.co.uk wrote: Is he possibly getting confused with Javascript? Thanks, Ash No, this guy is smarter than that -- he's pretty sharp -- so I listen to what he has to say. Here's an interesting link: http://www.sitepoint.com/best-programming-language-of-2013/ But the link does not divide languages between Web and Other -- other than Android Java, which I do not believe is also included in the above Java number. I think there is more going on here than what I know. For example, my college has numerous (over 3) JAVA classes filled to the max, whereas my PHP class was canceled due to lack of students. Granted the college could have advertised my PHP class more, but still there is an overwhelming demand for Java Programmers. My questions is Why? Just tell your teacher: Java isn't more popular than PHP as _web_-language ;) I think too, that he actually meant javascript, which is indeed a very popular client-side language. But javascript and PHP has different use-cases, thus saying one is more popular doesn't tell you anything about whether they are in competition against each other, or not (hint: they arent : :D). Cheers, tedd ___ tedd sperling t...@sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] PHP vs JAVA
2013/8/20 Tedd Sperling t...@sperling.com On Aug 20, 2013, at 10:29 AM, Sebastian Krebs krebs@gmail.com wrote: Just tell your teacher: Java isn't more popular than PHP as _web_-language ;) I think too, that he actually meant javascript, which is indeed a very popular client-side language. But javascript and PHP has different use-cases, thus saying one is more popular doesn't tell you anything about whether they are in competition against each other, or not (hint: they arent : :D). Two things: 1. He's not my teacher -- he is a fellow teacher AND a smart one! He knows the difference between Java and JavaScript. OKOK, sorry -_- But @topic: For example see http://w3techs.com/technologies/overview/programming_language/all Really: Java is a good and mature language, but it is not a web-language. 2. In life, you will find that popularity (often over which is best) is the main reason why things prosper. I am not saying, that Java is bad, or it is not popular. It is just not that popular in the web-ecosystem :) There was one statement I remember (I don't know, where I got it from): A static language doesn't fit very well into the dynamic web. :) Cheers, tedd ___ tedd sperling t...@sperling.com -- github.com/KingCrunch
Re: [PHP] PHP vs JAVA
2013/8/20 Lester Caine les...@lsces.co.uk Sebastian Krebs wrote: 1. He's not my teacher -- he is a fellow teacher AND a smart one! He knows the difference between Java and JavaScript. OKOK, sorry -_- But @topic: For example see http://w3techs.com/**technologies/overview/**programming_language/allhttp://w3techs.com/technologies/overview/programming_language/all Really: Java is a good and mature language, but it is not a web-language. 2. In life, you will find that popularity (often over which is best) is the main reason why things prosper. I think he is simply wrong in his interpretation of the facts. The number of websites powered by PHP vastly exceeds Java and every other language http://w3techs.com/**technologies/overview/**programming_language/allhttp://w3techs.com/technologies/overview/programming_language/all Says it all! But you would never use PHP for a distributed application, and then http://www.langpop.com/ comes into play when the fight is between Java and C/C++ and personally I'm happier with C/C++ than Java even on Android. But even though you would not use PHP for distributed applications, it still gets a good 4th in that chart as well. Exactly, but the initial explicitly states, that this is about web development :D Don't know, what I should think about langpop.com. A popularity listing, that doesn't take github (or any other repo hoster, than google code) into account? :? Its also quite outdated... -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=**contacthttp://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.**ukhttp://rainbowdigitalmedia.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] PHP vs JAVA
2013/8/20 Andy McKenzie amckenz...@gmail.com I'll chime in on this one. I've been job hunting recently, and I can say that while I've seen a lot of people asking for Java experience, I'm not sure I've seen a single posting asking specifically for PHP. There've been a few looking for Drupal, or Wordpress, but no You must be able to write PHP code to work here. Thats interesting. I am from Berlin and here, when you say you know PHP and a little bit of one, or two frameworks, they will jump onto you :D I can also say that the more I work with Java-based programs, the more I want to see Java written into history books as a terrible idea that sadly persisted until nearly 2014. As an example: I need to provide IT support to people using a tool written in Java. It turns out that if you install Java 7, the tool doesn't work at all. If you install Java 6 with the newest updates, it works, but occasionally crashes the entire computer. No, you have to have Java 6 update 22 in order for this software to be reliable. There are other tools I've used that failed completely on minor version switches, and that just plain SHOULDN'T HAPPEN. Yes, there are going to be minor changes when a language upgrades, that's why there are upgrades. But they're usually minor, in a This didn't work the way it was supposed to, so we fixed it kind of way. If you were taking advantage of that bug, you get knocked down, but the vast majority of software will keep running. Java doesn't seem to work that way, at least from an IT worker's perspective. Andy McKenzie On Tue, Aug 20, 2013 at 10:00 AM, Tedd Sperling t...@sperling.com wrote: Hi guys: A teacher at my college made the statement that JAVA for Web Development is more popular than PHP. Where can I go to prove this right or wrong -- and/or -- what references do any of you have to support your answer? (sounds like a teacher, huh?) Here are my two references: http://w3techs.com/technologies/details/pl-php/all/all http://w3techs.com/technologies/history_overview/programming_language/ms/y But I do not know how accurate they are. What say you? Cheers, tedd ___ tedd sperling t...@sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] PHP vs JAVA
2013/8/20 Andy McKenzie amckenz...@gmail.com On Tue, Aug 20, 2013 at 3:18 PM, Dan Munro d...@danmunro.com wrote: 1. There are no statement terminators. Lose your indentation for ANY reason and your program is well and truly screwed, in ways you can't imagine. 2. Python programs fail in the most ungraceful way I've ever seen in an interpreted programming language. 1. Indent properly. In php, if you put an open or close brace out of place your code will break in unexpected ways as well. If it's hard to tell if something is indented properly, your code should be refactored so that it is. 2. In my experience this has a lot to do with how some people use python and not python itself. I can't argue on point two, since that's where all of my worst failure have come from. But as to indenting, I have had the problem of opening a file on a new OS, only to find that the default editor there has wiped out my formatting. Who is with me? Thats a good point to restart the tabs-vs-spaces-discussion, isn't? *duckandrun* :D With PHP, that's not a big deal: as long as I put my braces in the right places, everything will continue to work. With Python -- or any whitespace delimited language -- it's fatal, and I have to hope I can exit without saving anything. Andy -- github.com/KingCrunch
Re: [PHP] PHP vs JAVA
2013/8/20 Steven Staples sstap...@mnsi.net My recent question was simply an attempt to get documentation to support which server-side Web Language is the most popular. Both PHP and Java can be used server-side. I also realize that Java is used for native Android because I also teach Mobile Application Development (MAD -- I even coined the name). So, I am up to my butt in languages (and people who think different than me) -- I'm just trying to get documentation to back up my what I think I know. Well, technically any language can be used server side, it is all on how you set up your server, no? No. But since node.js I lack an example :D But of course you need the link between the language and the network. I would tend to think that the biggest out there, is html/php/javascript... and next to that, would be asp, and then java. Do I have proof of this? No, can I get proof, I doubt it, and are there stats on this? To be honest, in my opinion, that would be like asking how big is the internet?. It is virtually an immeasurable object. There are so many websites out there, that you can't search them all... Of course you cannot search them _all_, but again the link: http://w3techs.com/technologies/overview/programming_language/all There are good hints, how the internet looks like. For example a hoster can simply look at the products he sell. Services like w3techs.com use the reports from the server themself (in most cases the headers), or the file-ending (doesn't work anymore that good, since most sites hide them ;)) and extrapolate this. Of course they are not exact, but I think they show the direction quite accurate. PHP is simple, and yet powerful to use, and is pretty much the standard for all hosting companies. Now, there is this link... http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html It shows Java as #1, and php as #5, but this is also for PROGRAMMING, does not specify web based programming vs desktop vs MAD (thanks tedd ;) ) so the numbers do not really speak out in this application. Also it is the Tiobe-Index. Although it is widely-referenced, the way it calculates their rankings is ... interesting. In fact it only tells you how loud a community around a specific language is. So for example maybe Java is #1, because it is so complex, that it leads to many questions in forums and on stackoverflow. Or PHP is only #5, because most communication is on IRC, or mailinglists. (disclaimer: Of course I faked this examples. Actually I have no idea how the communities around Java and PHP as a whole interacts primary, but I don't think, that they are all equal). I just think, that the Tiobe-Index has a completely different view on what is a popular language, than I have. Does it really matter? PHP is very huge, widely used, and I would even go so far as to say the 'norm' for website developers, and hosting providers. Nope, it doesn't matter :) But that is my $0.02, and for me, I have been with PHP for 7 years professionally, and in college I took VB.net, ASP.net, C++, JAVA and PHP. Only recently have I gotten into C# for desktop applications. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] how old is this version of PHP?
2013/8/19 Jeff Burcher j...@allredmetal.com I apologize if this is off topic, but this raises a question for me. Why can't new versions be backwards compatible? Is it really that difficult to accomplish? This has been a complaint of mine for years with Windows ever since we went from 95 to 98. I am an AS400 programmer and I have legacy programs written in RPG II, which died 20 years ago, and they still run fine on the newest version of AS400 or iSeries or Power System or whatever the heck it is called now. I also have PHP scripts that are many years old that work just fine the way they are, if a new version doesn't come along and make me have to reprogram for no reason just because it can't handle older code. Really, have Do loops and data calls changed that much over the years? I mean, all you do is set a condition, use a variable key field, and voila, data is pulled and processed, no big deal. Yeah, you can get fancy with it, but the core basics are still the same. I have been programming for over 35 years and like to think that once a program is built it should run forever. Do we just accept that we have to rewrite every program we ever wrote every time a new version comes out? A little extreme, but you get my point. Comments? Suggestions? My 2 cent: I hadn't any major issues with BC since 5.3 and from 5.2 it required a little bit to do, but was solveable (means: It wasn't complicated, but only an afternoon time to invest). Caine complaints from time to time his codebase here. That is nothing new and I am unsure how representative his statements are. Regards, Sebastian (I am also the kind of guy who thinks quality made hand tools from the 1800s are superior to many purchased today at Lowes or Home Depot.) Thanks, Jeff Burcher - IT Dept Allred Metal Stamping Works Making Metal Parts since 1946. -Original Message- From: Lester Caine [mailto:les...@lsces.co.uk] Sent: Monday, August 19, 2013 6:24 AM To: php-general@lists.php.net Subject: Re: [PHP] how old is this version of PHP? Larry Garfield wrote: 5.2.9 was released in February of 2009. 5.2 is completely retired and out of support. 5.3 is on security-only life-support. 5.4 is the legacy stable release. Yes, 5.2.9 IS that old. :-) Really, get a host that has made it into this decade. (GoDaddy apparently doesn't meet that qualification.) You're doing clients a disservice by allowing them to run such an ancient and unsupported version. While the statements are correct, many users are not in a position to move from their currently working systems to even 5.3 let alone 5.4. There is still a lot of legacy code that unless a few more people step up and help bring it forward for the many - non programming - users who are stuck with legacy applications, they will remain requiring 5.2 to run. ISPs got caught out when they arbitrarily moved accounts forward, and GoDaddy have even been caught by that, so maintaining a LTS version of PHP5.2 is the lesser evil ... Windows 2000 is supposed to be dead, but *I* still have sites reliant on it because the code and hardware is unsupported in even XP. Saying something is dead only works if there is an affordable way of moving forward ;) -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk -- 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 -- github.com/KingCrunch
Re: [PHP] Class Auto-Assigning to Variable
2013/8/7 Brian Smither bhsmit...@gmail.com I have a situation where, for some unknown reason, where each class that finishes its __contruct{} function, that class gets automatically assigned to a variable - other than the variable I specify. Conceptually: class Hello { private $_world = 'World'; __construct(){} } This isn't even valid PHP $ php -a Interactive shell php class Hello { private $_world = 'World'; __construct(){} } PHP Parse error: syntax error, unexpected '__construct' (T_STRING), expecting function (T_FUNCTION) in php shell code on line 1 php $clsHello = new Hello(); echo 'The variable $hello is '.gettype($hello).\n.print_r($hello,true); Output: The variable $hello is object Hello Object ( [_world:Hello:private] = World ) There is no statement in my application that assigns an instance of the class to another variable, the name being a lowercase variant of the class name. Would there be a PHP function that would do this as a side-effect? I am more interested in learning what is happening as opposed to rolling back to a previous version. (A backup copy functions fine. A file compare does not reveal any likely suspects.) PHP5.4.17-NTS-VC9 (Windows XP-SP3) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Fwd: What wrong am I doing now?
Hi, Just want to mention: ext/mysel is deprecated. Use MySQLi, or PDO_MYSQL instead. :) Regards, Sebastian 2013/7/24 Karl-Arne Gjersøyen karlar...@gmail.com http://www.php.net/manual/en/datetime.format.php have the solution. Sorry for asking before I look at php.net!!! Karl -- Forwarded message -- From: Karl-Arne Gjersøyen karlar...@gmail.com Date: 2013/7/24 Subject: What wrong am I doing now? To: PHP Mailinglist php-general@lists.php.net mysql SELECT DATE_FORMAT(dato, '%e-%c-%Y') FROM transportdokument WHERE dato = '2013-07-20' AND dato = '2013-07-24' GROUP BY dato DESC; +---+ | DATE_FORMAT(dato, '%e-%c-%Y') | +---+ | 24-7-2013 | | 23-7-2013 | +---+ 2 rows in set (0.00 sec) mysql // My PHP code looks like this. // - $sql = SELECT DATE_FORMAT(dato, '%e-%c-%Y') FROM transportdokument WHERE dato = '2013-07-20' AND dato = '2013-07-24' GROUP BY dato DESC; $resultat = mysql_query($sql, $tilkobling) or die(mysql_error()); while($rad = mysql_fetch_array($resultat)){ $dato = $rad['dato']; var_dump($dato); I gott NULL,NULL here and believe it is something with my PHP Source that is wrong when using DATE_FORMAT. As you see above it work in terminal. I hope this not is off-topic for the list. If so, I am sorry for it and hope you can give me advice about a good MySQL list for newbie's. Thanks again for your help! Karl -- github.com/KingCrunch
Re: [PHP] I am completely lost and need an advice (beginner)
2013/7/18 Carsten Jensen to...@tomse.dk On 07/18/2013 09:08 PM, php colos wrote: Hello world! I'm trying to learn PHP ( first programming language that I learn) and I feel kinda lost. I've read PHP programming 3rd edition( O'reilly), 'getting good with PHP' by Andrew Burgees and some tutorials on the internet but can't code something more complex than 'hello world'. I do understand functions/values/operators/control structures, etc but as I said, I feel that I can't use the language. Am I reading the wrong books for a beginner? Any advices? *Apologies if this email might seem confusing. :) Richard As others have mentioned, reading only isn't a good thing. You'll need to code alongside reading. You also might need to have a goal/project to motivate you to code. Starting small is a good thing. Or you could help out some of the smaller php projects that have only a few coders. Fixing bugs in a project can be a great help, and you'll learn a lot. If you don't have any project in mind, you can go to codecademy.com or some of the other interactive learning sites to start coding. I just checked, they've implemented PHP now, I haven't tried this. But the javascript course is great. cheers Carsten Same here: Just reading doesn't help you very much. You should also consider reading books about programming in general, or even better get in contact with more (or less ;)) experienced programmers, because in my experience learning the syntax and writing code is just a very minor part. Its more important to know how to solve the problems (in a way, that works tomorrow too ;)) is more important. And as a side effect getting help can prevent frustration, if you are stuck in a problem ;) Regards, Sebastian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] phpdocumentor with PHP5.4
You can simply update phpdocumentor Am 07.07.2013 17:10 schrieb Lester Caine les...@lsces.co.uk: Anybody have phpdocumentor running with PHP5.4? I'm convinced that the errors my copy is throwing are due to e_strict, but I've confirmed that I have the right ini file ( all the needed extensions load ) and I'm getting error_reporting showing 22527 with e_strict off and 24575 with e_strict on - so at least it is changing the setting? Once again I'm wasting hours getting something which I have had running fine on the older servers to actually work in a new setup. In this case phpdocumentor seems to suggesting *IT* needs PHP5.3 but the main script also switched e_strict off anyway, so 5.4 should work as well? -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=**contacthttp://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.**ukhttp://rainbowdigitalmedia.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] phpdocumentor with PHP5.4
I meant: PhpDocumentor 2 Am 07.07.2013 17:44 schrieb les...@lsces.co.uk: It's a clean install via PEAR a couple of hours ago! Sent from my android device. -Original Message- From: Sebastian Krebs krebs@gmail.com To: Lester Caine les...@lsces.co.uk Cc: PHP General List php-general@lists.php.net Sent: Sun, 07 Jul 2013 16:41 Subject: Re: [PHP] phpdocumentor with PHP5.4 You can simply update phpdocumentor Am 07.07.2013 17 0707201317:10 schrieb Lester Caine les...@lsces.co.uk: Anybody have phpdocumentor running with PHP5.4? I'm convinced that the errors my copy is throwing are due to e_strict, but I've confirmed that I have the right ini file ( all the needed extensions load ) and I'm getting error_reporting showing 22527 with e_strict off and 24575 with e_strict on - so at least it is changing the setting? Once again I'm wasting hours getting something which I have had running fine on the older servers to actually work in a new setup. In this case phpdocumentor seems to suggesting *IT* needs PHP5.3 but the main script also switched e_strict off anyway, so 5.4 should work as well? -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=**contact http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.**uk http://rainbowdigitalmedia.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] phpdocumentor with PHP5.4
You can submit a pull request for that 2013/7/7 Lester Caine les...@lsces.co.uk Sebastian Krebs wrote: I meant: PhpDocumentor 2 Problem solved ... Notes on https://github.com/**phpDocumentor/phpDocumentor2https://github.com/phpDocumentor/phpDocumentor2need a little update to correct the installation notes to use the beta builds rather than alpha ones. -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=**contacthttp://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.**ukhttp://rainbowdigitalmedia.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Re: need some regex help to strip out // comments but not http:// urls
2013/5/29 Matijn Woudt tijn...@gmail.com On Wed, May 29, 2013 at 10:51 PM, Sebastian Krebs krebs@gmail.comwrote: 2013/5/29 Matijn Woudt tijn...@gmail.com On Wed, May 29, 2013 at 6:08 PM, Sean Greenslade zootboys...@gmail.com wrote: On Wed, May 29, 2013 at 9:57 AM, Jonesy gm...@jonz.net wrote: On Tue, 28 May 2013 14:17:06 -0700, Daevid Vincent wrote: I'm adding some minification to our cache.class.php and am running into an edge case that is causing me grief. I want to remove all comments of the // variety, HOWEVER I don't want to remove URLs... KISS. To make it simple, straight-forward, and understandable next year when I have to re-read what I've written: I'd change all :// to QqQ -- or any unlikely text string. Then I'd do whatever needs to be done to the // occurances. Finally, I'd change all QqQ back to ://. Jonesy Wow. This is just a spectacularly bad suggestion. First off, this task is probably a bit beyond the capabilities of a regex. Yes, you may be able to come up with something that works 99% of the time, but this is really a job for a parser of some sort. I'm sorry I don't have any suggestions on exactly where to go with that, however I'm sure Google can be of assistance. The main problem is that regex doesn't understand context. It just blindly finds patterns. A parser understands context, and can figure out which //'s are comments and which are something else. As a bonus, it can probably understand other forms of comments like /* */, which regex would completely die on. It is possible to write a whole parser as a single regex, being it terribly long and complex. No, it isn't. It's better if you throw some smart words on the screen if you want to convince someone. Just thinking about it, it makes sense as a true regular expression can only describe a regular language, and I think all the programming languages are not regular languages. But, We have PHP PCRE with extensions like Recursive patterns[1] and Back references[2], which can describe much more than just a regular language. And I do believe it would be able to handle it. Too bad it probably takes months to complete a regular expression like this. Then you start as soon as possible, so that you not realitze, that this is wrong, when it is too late. I am not going to start explaining this again, because it becomes a waste of time. You call it smart words on the screen, I call it advice. - Matijn [1] http://php.net/manual/en/regexp.reference.recursive.php [2] http://php.net/manual/en/regexp.reference.back-references.php -- github.com/KingCrunch
Re: [PHP] Re: need some regex help to strip out // comments but not http:// urls
2013/5/29 Matijn Woudt tijn...@gmail.com On Wed, May 29, 2013 at 6:08 PM, Sean Greenslade zootboys...@gmail.com wrote: On Wed, May 29, 2013 at 9:57 AM, Jonesy gm...@jonz.net wrote: On Tue, 28 May 2013 14:17:06 -0700, Daevid Vincent wrote: I'm adding some minification to our cache.class.php and am running into an edge case that is causing me grief. I want to remove all comments of the // variety, HOWEVER I don't want to remove URLs... KISS. To make it simple, straight-forward, and understandable next year when I have to re-read what I've written: I'd change all :// to QqQ -- or any unlikely text string. Then I'd do whatever needs to be done to the // occurances. Finally, I'd change all QqQ back to ://. Jonesy Wow. This is just a spectacularly bad suggestion. First off, this task is probably a bit beyond the capabilities of a regex. Yes, you may be able to come up with something that works 99% of the time, but this is really a job for a parser of some sort. I'm sorry I don't have any suggestions on exactly where to go with that, however I'm sure Google can be of assistance. The main problem is that regex doesn't understand context. It just blindly finds patterns. A parser understands context, and can figure out which //'s are comments and which are something else. As a bonus, it can probably understand other forms of comments like /* */, which regex would completely die on. It is possible to write a whole parser as a single regex, being it terribly long and complex. No, it isn't. That said, there's no other simple syntax that would work, for example in javascript you could to the following: var http = 5; switch(value) { case http:// Http case here! (this whould not be deleted) // Do something } But most likely you wouldn't care about that.. - Matijn -- github.com/KingCrunch
Re: [PHP] Header Keep-Alive
2013/5/27 Al n...@ridersite.org I'm trying to increase the connection timeout; but can't get it to work. Note: Keep-Alive gets repeated. I'm using: header(Connection: Keep-Alive); header(Keep-Alive: timeout=9, max=100); Set the second optional argument to true See http://de.php.net/manual/en/function.header.php I get: (Status-Line) HTTP/1.1 200 OK DateMon, 27 May 2013 20:19:54 GMT Server Apache Connection Keep-Alive, Keep-Alive Keep-Alive timeout=5, max=100 Expires Thu, 19 Nov 1981 08:52:00 GMT Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma no-cache Content-Encodinggzip VaryAccept-Encoding,User-Agent Set-Cookie Coach::VermontCamp2013_**setupMode=** 58d7e534bec4ec57634c78caa59d8d**b2; expires=Sat, 23-Nov-2013 20:19:55 GMT; path=/Coach/; domain=.ridersite.org Transfer-Encoding chunked Content-Typetext/html; charset=utf-8 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] A Good OOP Tutorial/Read?
2013/5/17 Tedd Sperling tedd.sperl...@gmail.com Nick: I thank you for your addition, but what you provided did nothing to explain the difference between abstract and interface. In your example: An abstract Shape with Circle and Square inheriting. OR An interface Shape with Circle and Square implementing. Does exactly the same thing -- so where's the difference? - The first one allows to contain implemented methods. Interfaces enforce contract only, which makes them more stable on the long run. Sooner or later (or right from the beginning) someone _will_ implement a method in that class, which will loosen the separation between the contract and the implementation. And then it begins, that it is hard to distinguish, what from this class is contract (and should _never_ change without a good reason) and what is implementation, that can change. - It is semantically different as first one states Circle _is a_ Shape, whereas interfaces defines their relationship more like Circle _behaves like_ a Shape. - In many languages you can only extend from one class. Of course: Technically they do the same, but thats not the point ;) Also technically you don't _require_ interfaces at all. As mentioned: Most of this happens in ones mind. For example if you change an interface, you should _always_ expect to break something ;) Most of OOP isn't about syntax or technical features anyway, but it is about concepts (design and so on). And as a sidenote: I don't say (and don't believe ;)) that my explanation is completely academically correct ;) Also, your: Please make an effort to understand polymorphic concepts of OOP as they are rudimentary. Without that one will never grasp OO Patterns (Gang of Four). Was more insulting than helpful. Polymorphism was not the question asked. Clearly the getArea() method is polymorphic and overridden in both Circle and Shape classes and also in BOTH abstract and interface examples. Additionally, I'm not sure what: (int double side) means. Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com - On May 16, 2013, at 8:47 PM, Nick Khamis sym...@gmail.com wrote: interface Shape { public double getArea(); } class Circle implements Shape { double radius; public Circle(int double radius) { this.radius = radius; } public double getArea() { return (radius * radius * 3.1415); } } class Square implements Shape { double side; public Square(int double side) { this.side = side; } double getArea() { return (side * side); } } Please make an effort to understand polymorphic concepts of OOP as they are rudimentary. Without that one will never grasp OO Patterns (Gang of Four). Ninus. On 5/16/13, Tedd Sperling tedd.sperl...@gmail.com wrote: Thanks to both Bastien and Sebastian: While I understand that an interface is like an abstract Class, in that you don't have to flesh-out your methods, but rather where you define exactly how Classes who implement that interface will be required to flesh-out those methods. But so what? What's the point? Without giving me complicated examples, just give me one simple example that illustrates the advantage of using an interface over writing a new Class where you flesh-out whatever methods you want. After all, an interface requires the same thing, does it not? As such, I just don't see the advantage interfaces bring. Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com -- 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 -- github.com/KingCrunch
Re: [PHP] A Good OOP Tutorial/Read?
2013/5/16 Tedd Sperling tedd.sperl...@gmail.com -Dan: I teach this stuff and still don't fully understand the why/when for interfaces. Even the guru's I talk with can't give me a good explanation as to what the advantages are in using them. I've done a lot of experimenting and can't see any advantage for them other than grouping different classes together and creating a new data-tytpe. An interface is like an contract: It doesn't do anything itself, but every class, that implements it must follow. This isn't only about the signature of the methods, but also about the semantics, which is ideally described directly in the methods comment (DocBlocks). On the other hand the class is completely free on how it fulfill the contract. For example: A QueueInterface. It probably defines the signatures for (at least) enqueue() and dequeue() and their semantics: enqueue() enqueues an element at the end of the queue and may fail with an XY-Exception, when the queue is full, deuqeue() dequeues an element from the front of the queue and throws an Z-Exception, when the queue is empty. An implementing class is free to implement this on top of a database, or an array, as well as the class is free to extend it with other methods as it like. Of course you could implement it as abstract class, but this leads (instantly, or later) to a mix between contract and implementation details, that (by the way) should be up to the implementing class anyway. Now that you have one, or more classes implementing that interface you can type hint against this contract and only against this one, because it is better to always hint against the most-simple type the methods requires. In this example this means: I, the method x(), expect a queue and I am completely uninterested in how it is implemented, or what other features it provides, because I don't use them anyway. Now you can give me a database-cursor, or a wrapped array as long as they _behave_ like a queue (-- implementing that interface). As a side effect: Sometimes it is more fail-safe, because if you change signatures, or add methods, you'll face the errors from wrongly implemented classes instantly ;) Oh: And you are not forced to extend a class :) Lets say I have a Comparable-interface and a User-Class. Would Comparable be a class, I have to extend it, which makes it impossible to extend any other class and also the semantic is wrong: A User _behaves_ like a Comparable, but it _is not_ a Comparable. (For me implementing an interface is usually more a behaves like, looks like, or provides, whereas extending a class is directly a is a-relationship). This said, the difference between an interface and an abstract class is mostly in the head: An abstract class is in my opinion never such a strict contract, like an interface, especially because you can always leave the contract-only-restriction by implementing something into the class, what is then directly inherited by the subclasses. My 2 cent :) But for me this idea works quite fine :D Regards, Sebastian Other than that, from my perspective interfaces are mythicode. So, if you find a good reference, please let me know. Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com On May 16, 2013, at 11:11 AM, Dan Joseph dmjos...@gmail.com wrote: Thanks! This looks like a good start. Covers some things I have questions on. I like his approach. Now I just need something advanced to continue on after this. I'd like to learn more about extending, interfaces, abstracts, and why/when they should be used. Appreciate it! -Dan On Thu, May 16, 2013 at 11:01 AM, Francisco C Soares dotjun...@gmail.comwrote: On 05/16/2013 11:55 AM, Dan Joseph wrote: Hey Folks, I'm looking to refine my PHP 5 OOP skills. I know the basics, understand patterns, but have clearly missed a few things along the way. Do any of you have some real good PHP 5 OOP tutorials/reads bookmarked you could share? Something other than php.net/oop5. Try, Tente, http://www.killerphp.com/tutorials/object-oriented-php/ Success! Sucesso! ___ Francisco C Soares ( *Junior* ) 403790c89847cdbe5a262146de8fb93139c4 BLOG dotjunior.blogspot.com -- -Dan Joseph http://www.danjoseph.me http://www.dansrollingbbq.com http://www.youtube.com/DansRollingBBQ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Need a tool to minimize HTML before storing in memecache
2013/5/3 Daevid Vincent dae...@daevid.com -Original Message- From: Marco Behnke [mailto:ma...@behnke.biz] Sent: Friday, May 03, 2013 12:01 PM To: Daevid Vincent; php php-general@lists.php.net Subject: Re: [PHP] Need a tool to minimize HTML before storing in memecache If you really have that much traffic, then memcache isn't your answer to caching. It is as slow as a fast database. That's not entirely true. You should use APC caching instead. APC will also handle a lot of bytecode caching. We have both. If you want to go with tidy and surf around the php issues you could optimize the single html parts, before glueing everything together. That would require much more work than simply getting and to work. And honestly I've been hacking around Tidy so much at this point with regex to minify the output, that I'm even wondering if Tidy is worth the both anymore. Not sure what else it will give me. Maybe google page speed is worth a look for you too? We have over 1,000 servers in house and also distributed across nodes in various cities and countries. Really? Ever considered HTTP-Caching, or even Load-Balancing including ESI? With the loggedin flag, you can save two versions of your rendered, one for loggedin users and for not logged in users. That saves you php code in your template and you can use tidy. And for any other variables you can load the dynamic data after the page load. I gave simplistic examples for the sake of illustration. With tidy, have you tried http://tidy.sourceforge.net/docs/quickref.html#preserve-entities http://tidy.sourceforge.net/docs/quickref.html#fix-uri Yes. See below. I posted all the flags I have tried and I too thought those were the key, but sadly not. Regards, Marco Am 03.05.13 19:40, schrieb Daevid Vincent: Well we get about 30,000 page hits PER SECOND. So we have a template engine that generates a page using PHP/MySQL and populates it as everyone else does with the generic content. Then we store THAT rendered page in a cache (memcache pool as well as a local copy on each server). HOWEVER, there are of course dynamic parts of the page that can't be cached or we'd be making a cached page for every unique user. So things like their ?= $username ?, or maybe parts of the page change based up their membership ?php if ($loggedin == true) { ?, or maybe parts of the page rotate different content (modules if you like). Therefore we are trying to mininimize/compress the cached pages that need to be served by removing all !-- -- and /* */ and // and whitespace and other stuff. When you have this much data to serve that fast, those few characters here and there add up quickly in bandwidth and space. As well as render time for both apache and the client's browser's parser. Dig? -Original Message- From: ma...@behnke.biz [mailto:ma...@behnke.biz] Sent: Friday, May 03, 2013 4:28 AM To: Daevid Vincent; 'php-general General' Subject: RE: [PHP] Need a tool to minimize HTML before storing in memecache But why are you caching uncompiled php code? Daevid Vincent dae...@daevid.com hat am 2. Mai 2013 um 23:21 geschrieben: While that may be true for most users, I see no reason that it should limit or force me to a certain use case given that dynamic pages make up the vast majority of web pages served. Secondly, there are 8 billion options in Tidy to configure it, I would be astonished if they were so short-sighted to not have one to disable converting and to lt; and gt; as they do for all sorts of other things like quotes, ampersands, etc. I just don't know which flag this falls under or what combination of flags I'm setting that is causing this to happen. Barring that little snag, it works like a champ. -Original Message- From: ma...@behnke.biz [mailto:ma...@behnke.biz] Sent: Thursday, May 02, 2013 4:55 AM To: Daevid Vincent; 'php-general General' Subject: RE: [PHP] Need a tool to minimize HTML before storing in memecache This is because tidy is for optimizing HTML, not for optimizing PHP. Daevid Vincent dae...@daevid.com hat am 2. Mai 2013 um 02:20 geschrieben: So I took the time to install Tidy extension and wedge it into my code. Now there is one thing that is killing me and breaking all my pages. This is what I WANT the result to be: link rel=stylesheet type=text/css href=/templates/?= $layout_id ?/css/styles.css / link rel=stylesheet type=text/css href=/templates/?= $layout_id ?/css/retina.css media=only screen and (-webkit-min-device-pixel-ratio: 2) / Which then 'renders' out to this normally without Tidy: link rel=stylesheet type=text/css href=/templates/2/css/styles.css / link rel=stylesheet
Re: [PHP] Newbie Question - Parse XML with PHP...
A webpage is a file, that (usually) a browser downloads and parses. You'll do exactly the same :-) I don't know exactly, but you can try to pass the URL directly to simplexml_load_file(). If this doesn't work, download the content (for example with file_get_contents()) and pass it to simplexml_load_string(). There are obviously many other approaches, but you should now have an idea :-) Or you use a specialized library like Guzzle. Am 19.04.2013 22:17 schrieb dealTek deal...@gmail.com: Hi all, newbie - just starting with trying to parse XML... $mylist = simplexml_load_file('thelist.xml'); then use a foreach to echo the data... ?php $mysongs = simplexml_load_file('songs.xml'); foreach ($mysongs as $songinfo) { $title=$songinfo-title; $artist=$songinfo-artist; $date=$songinfo['dateplayed']; echo $title.' --- '; echo $artist.' --- '; echo $date.' --- '; echo ' /br '; } ? that I get ... Question: how do you use $mylist when the xml is not as a file but is returned on a web page? an example of the real xml I am trying to work with is like this demo below Goal : when this response comes back - I would like to be able to get the data as php and then update the database example ?xml version=1.0 encoding=UTF-8? response result1/result result-textSUCCESS/result-text transaction-id1865264174/transaction-id result-code100/result-code authorization-code123456/authorization-code avs-resultN/avs-result cvv-resultN/cvv-result action-typesale/action-type amount12.00/amount ip-address::1/ip-address industryecommerce/industry processor-idccprocessora/processor-id currencyUSD/currency order-descriptionSmall Order/order-description merchant-defined-field-1Red/merchant-defined-field-1 merchant-defined-field-2Medium/merchant-defined-field-2 order-id1234/order-id tax-amount2.00/tax-amount shipping-amount0.00/shipping-amount billing first-nameJohn/first-name last-nameSmith/last-name address11234 Main St./address1 cityBeverly Hills/city stateCA/state postal90210/postal countryUS/country phone555-555-/phone emailt...@example.com/email companyAcme, Inc./company cc-number40**0002/cc-number cc-exp0118/cc-exp /billing shipping first-nameMary/first-name last-nameSmith/last-name address11234 Main St./address1 cityBeverly Hills/city stateCA/state postal90210/postal countryUS/country address2Unit #2/address2 /shipping product product-codeSKU-123456/product-code descriptiontest product description/description commodity-codeabc/commodity-code unit-of-measure1/unit-of-measure unit-cost5./unit-cost quantity1./quantity total-amount7.00/total-amount tax-amount2.00/tax-amount tax-rate1.00/tax-rate discount-amount2.00/discount-amount discount-rate1.00/discount-rate tax-typesales/tax-type alternate-tax-id12345/alternate-tax-id /product product product-codeSKU-123456/product-code descriptiontest 2 product description/description commodity-codeabc/commodity-code unit-of-measure2/unit-of-measure unit-cost2.5000/unit-cost quantity2./quantity total-amount7.00/total-amount tax-amount2.00/tax-amount tax-rate1.00/tax-rate discount-amount2.00/discount-amount discount-rate1.00/discount-rate tax-typesales/tax-type alternate-tax-id12345/alternate-tax-id /product /response -- Thanks, Dave - DealTek deal...@gmail.com [db-3]
Re: [PHP] Detecting massive web hits
Nginx has builtin support for this and I assume, that there is something similar for Apache. I don't think PHP is the right tool. Am 12.04.2013 17:24 schrieb Angela Barone ang...@italian-getaways.com: Does anyone know if there's a ready-made script that detects if someone hits multiple web pages within seconds of each other and then can temporarily ban them by IP from accessing our site? Looking through the logs, I see someone/something hit each and every page of a site I work on within only a few seconds of each other. I seriously doubt they are a customer. ;) I'd appreciate any insights. Thank you, Angela -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] application level variable file
2013/3/22 inu...@gmail.com I am very new to the PHP application and would like to create a new project. I would like to have a file to save my application level variable and functions. I would like to know does PHP have any default file name and file path for this file like Web.config file for ASP.Net and Application.cfm for ColdFusion? Your help and information is great appreciated, Do you mean index.php and Document-Root? Both is defined/configured by the webserver Regards, Inungh -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] significance of escape character in string in PHP
2013/3/18 Ken Robinson kenrb...@rbnsn.com On 18.03.2013 09:10, Norah Jones wrote: I am having an string which was have few ' (single quote) and few (double quotes) and was not able to insert into the mysql database. I have replaced them with \' and \ and everything is fine. Though this are fine now but don't understand the working and I could have missed few corner cases also. Please suggest the working and also if there is some better way to achieve this. You should be using either mysql_real_escape_string or mysqli_real_escape_string (preferably the later) depending on how you're accessing the DB. You shouldn't use ext/mysql at all! Use prepared statements with PDO_MYSQL or MySQLi Ken -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Type of a variable in PHP
2013/3/15 Kevin Peterson qh.res...@gmail.com Have two questions - 1. How to find type of a variable in PHP. gettype(), or one of the is_*()-functions. But for me more interesting for me: Why do you _need_ this? 2. How to find the type of an array in PHP. An array is of type array :) is_array() or again gettype(). Can you maybe describe what you want to achieve? In a dynamically typed language it is rarely _required_, that you know the _concrete_ type. Please help. -- github.com/KingCrunch
Re: [PHP] PHP context editor
2013/3/15 Karim Geiger gei...@b1-systems.de Hi Georg, On Thu, 2013-03-14 at 23:10 +0100, georg wrote: hello, annyone knows of some good PHP context editor freeware ? (tired of missing out on trivials like ; ) I don't know exactly what you mean by a context editor but if you want an editor with syntax highlighting try eclipse for an complete IDE (Multiplatform), notepad++ on Windows, textwrangler on Mac or vim on Linux Or PhpStorm on Linux (multiplatform) :) Or Netbeans on Linux (multiplatform too). Or gedit on Gnome/Linux, or or or ... vim is not the end of what can a linux desktop can provide :D Regards -- Karim Geiger B1 Systems GmbH Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537 -- github.com/KingCrunch
Re: [PHP] variable type - conversion/checking
2013/3/16 Ashley Sheridan a...@ashleysheridan.co.uk tamouse mailing lists tamouse.li...@gmail.com wrote: On Fri, Mar 15, 2013 at 4:00 PM, Ashley Sheridan a...@ashleysheridan.co.ukwrote: ** On Fri, 2013-03-15 at 04:57 -0500, tamouse mailing lists wrote: On Fri, Mar 15, 2013 at 3:55 AM, Peter Ford p...@justcroft.com wrote: On 15/03/13 06:21, Jim Lucas wrote: On 3/14/2013 4:05 PM, Matijn Woudt wrote: On Thu, Mar 14, 2013 at 11:44 PM, Jim Lucas li...@cmsws.com wrote: On 03/14/2013 11:50 AM, Samuel Lopes Grigolato wrote: Something like if (is_numeric($var) $var == floor($var)) will do the trick. I don't know if there's a better (more elegant) way. On Thu, Mar 14, 2013 at 3:09 PM, Matijn Woudttijn...@gmail.com wrote: On Thu, Mar 14, 2013 at 7:02 PM, georggeorg.chamb...@telia.com** wrote: Hi, I have tried to find a way to check if a character string is possible to test whether it is convertible to an intger ! any suggestion ? BR georg You could use is_numeric for that, though it also accepts floats. - Matijn for that type of test I have always used this: if ( $val == (int)$val ) { http://www.php.net/manual/en/**language.types.integer.php#** language.types.integer.casting http://www.php.net/manual/en/language.types.integer.php#language.types.integer.casting I hope you're not serious about this... When comparing a string and an int, PHP will translate the string to int too, and of course they will always be equal then. So: $a = abc; if($a == (int)$a) echo YES; else echo NO; Will always return YES. - Matijn H... Interesting. Looking back at my code base where I thought I was doing that, turns out the final results were not that, but this: $value = asdf1234; if ( $value === (string)intval($value) ) { Looking back at the OP's request and after a little further searching, it seems that there might be a better possible solution for what the OP is requesting. ?php $values = array(asdf1234, 123.123, 123); foreach ( $values AS $value ) { echo $value; if ( ctype_digit($value) ) { echo ' - is all digits'; } else { echo ' - is NOT all digits'; } echo 'br /'.PHP_EOL; } returns... asdf1234 - is NOT all digits 123.123 - is NOT all digits 123 - is all digits http://www.php.net/manual/en/function.ctype-digit.php An important note: This function expects a string to be useful, so for example passing in an integer may not return the expected result. However, also note that HTML forms will result in numeric strings and not integers. See also the types section of the manual. -- Jim Integers can be negative too: I suspect your test would reject a leading '-'... For my money, `is_numeric()` does just what I want. The thing is, is_numeric() will not check if a string is a valid int, but any valid number, including a float. For something like this, wouldn't a regex be better? if(preg_match('/^\-?\d+$/', $string)) echo int Thanks, Ash http://www.ashleysheridan.co.uk That is so about is_numeric(), but once I know it's a numeric, coercing it to just an int is easy. *Validating*, rather than just assuring, that a string is an integer is another matter; if you need to give feedback to the user, etc., in which case a Regex is better. (One small nit, + is possible on integers, too.) The op wasn't about casting a string to an int but detecting if a string was just a string representation of an int. Hence using a regex to determine that. Regular expressions are not just about giving feedback to the user. Guess regex are the only useful solution here. When you consider to use built-in functions, just remember, that for example '0xAF' is an integer too, but '42.00' isn't. Thanks, Ash http://www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] variable type - conversion/checking
2013/3/16 Andrew Ballard aball...@gmail.com I suppose one could try something like this: if (is_string($val) $val === (string)(int)$val) If $val is an integer masquerading as a string, it should be identical to the original string when cast back to a string, shouldn't it? (I can't try it right now.) It is semantically equivalent to $val == (int) $val and as far as I remember (I didn't read everything completely) this were mentioned. I didn't read, whether or not, it was accepted as solution ;) Andrew -- github.com/KingCrunch
Re: [PHP] Mystery foreach error
2013/3/14 David Harkness davi...@highgearmedia.com On Wed, Mar 13, 2013 at 4:44 PM, Angela Barone ang...@italian-getaways.comwrote: I ran across if(array_key_exists) and it seems to work. How does that differ from if(isset($states[$state]))? Hi Angela, isset() will return false for an array key 'foo' mapped to a null value whereas array_key_exists() will return true. The latter asks Is this key in the array? whereas isset() adds and is its value not null? While isset() is every-so-slightly faster, this should not be a concern. Use whichever makes sense for the context here. Since you don't stick null values into the array, I prefer the isset() form because the syntax reads better to me. Just a minor addition: Because 'null' is the representation of nothing array_key_exists() and isset() can be treated as semantically equivalent. Another approach (in my eyes the cleaner one ;)) is to simply _ensure_ that the keys I want to use exists. Of course this only works in cases, where the key is not dynamical, or the dynamic keys are known, which is not the case here, it seems. $defaults = array('stateNames' = array(), 'states' = array()); $values = array_merge($defaults, $values); $values['states'] = array_merge(array_fill_keys($values['stateNames'], null), $values['states']); if (!$values[$myState]) { } Peace, David -- github.com/KingCrunch
Re: [PHP] Mystery foreach error
2013/3/14 David Harkness davi...@highgearmedia.com On Wed, Mar 13, 2013 at 5:10 PM, Sebastian Krebs krebs@gmail.comwrote: Because 'null' is the representation of nothing array_key_exists() and isset() can be treated as semantically equivalent. As I said, these functions return different results for null values. It won't matter for Angela since she isn't storing null in the array, though. Thats exactly, what I tried to say :) Peace, David -- github.com/KingCrunch
Re: [PHP] Re: UNLESS Statement Equivalent
2013/3/12 Ford, Mike m.f...@leedsmet.ac.uk -Original Message- From: Maciek Sokolewicz [mailto:tula...@gmail.com] On Behalf Of Maciek Sokolewicz Sent: 11 March 2013 22:44 unless ( $a and $b ) = if ( ! ($a and $b) ) So in simple terms, just stick a ! (or the keyword not) in front of your expression, and you'll have exactly what you want: if( not ( ($current_page == $saved_page) and ($current_ip == $saved_ip) and ($current_dt ($saved_dt + 3600) ) ) { Whilst this is true as far as it goes, I would suggest applying deMorgan's laws to simplify slightly to if ( ($current_page != $saved_page) or ($current_ip != $saved_ip) or ($current_dt = ($saved_dt + 3600) ) ) If it is simpler depends, because not ($everything $must $be $true) is sometimes more logical :) Also, the keyword versions of the Boolean operators are very low priority, which is why you need all those extra parentheses -- if you switch to the symbolic versions, you can leave all the internal parentheses out to give: if ($current_page != $saved_page || $current_ip != $saved_ip || $current_dt = $saved_dt + 3600) Just to throw that in if (array($current_page, $current_ip, $current_dt) != array($saved_page, $saved_ip, $saved_dt + 3600)) This at least includes the information, that you have to sets of values, that should be equal :) Cheers! Mike -- Mike Ford, Electronic Information Developer, Libraries and Learning Innovation, Portland PD507, City Campus, Leeds Metropolitan University, Portland Way, LEEDS, LS1 3HE, United Kingdom E: m.f...@leedsmet.ac.uk T: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Holding datetimes in a DB.
2013/3/2 tamouse mailing lists tamouse.li...@gmail.com On Fri, Mar 1, 2013 at 11:53 AM, Matijn Woudt tijn...@gmail.com wrote: On Fri, Mar 1, 2013 at 11:49 AM, Richard Quadling rquadl...@gmail.com wrote: Hi. My heads trying to remember something I may or may not have known to start with. If I hold datetimes in a DB in UTC and can represent a date to a user based upon a user preference Timezone (not an offset, but a real timezone : Europe/Berlin, etc.) am I missing anything? Richard. I would only use this if you're planning to have servers all around the world in different timezones, then it would be easier to interchange data. Otherwise, stick with ur local timezone and it will save you a lot of unneeded timezone conversions probably. - Matijn This may be just me, but I've always preferred my servers, database, and such to run UTC, and let users select their own time zone they'd like to see. Well, imo it depends ;) There are cases, where it is interesting to know, when from the users point of view they have created the entity (like a blog post, a comment, or something like that). The TZ is part of the data and converting it silently to UTC is always data-loss. So in most cases it is OK, but not in every :) You can still convert from entity-TZ to UTC to user-TZ later. Its just one additional step. Regards, Sebastian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Stupid question
2013/2/27 tamouse mailing lists tamouse.li...@gmail.com On Tue, Feb 26, 2013 at 4:41 PM, Jim Lucas li...@cmsws.com wrote: On 02/26/2013 01:27 PM, Curtis Maurand wrote: I have the following: $dsn = mysqli://$username:$password@$hostname2/$database; $options = array( 'debug' = 3, 'result_buffering' = false, ); $dbh = MDB2::factory($dsn, $options); if (PEAR::isError($mdb2)) { die($mdb2-getMessage()); } function tallyCart($_u_id,$dbh){ while($row = $result-fetchrow(MDB2_FETCHMODE_ASSOC)) { Talking in code. The above two lines tell me... $dbh != $result isset($result) === false $_showCheckOut=1; $_pdetail=new ProductDetail($row{'product_ID'}, $row{'product_Quantity'}, $_u_id); $_getSubTotal += $_pdetail-_subTotal; $_counter++; } } I'm getting: Call to undefined method MDB2_Error::fetchrow() anyone have any ideas? Can I not pass a database handle to a function? Thanks, Curtis -- Jim Lucas http://www.cmsws.com/ http://www.cmsws.com/examples/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Well, *I* have a stupid question: is $lhv = expr the same as $lhv = expr ?? Yes :) Because an operator = doesn't exists, thus the lexer will split them into the tokens = , or = WHITESPACE respectively. The parser again ignores whitespaces. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Very Large File Splatter
2013/2/22 Brian Smither bhsmit...@gmail.com PHP 5.4.4-TS-VC9 on Windows XP SP3 NTFS non-system drive with 18GB free. I dare not try to replicate this. As such, I cannot firmly place the blame on PHP. I have peppered a PHP application with a call to a function which appends-only to a logfile the parameters passed to it. Each pass of the application creates many MB of content. It is conceivable that I ran out of hard drive space. When that which what I was working on seemed to be acting very weird, I rebooted the computer only to see thousands of lines scroll by from Windows repairing the file system. I discovered logfile contents in many dozens of files. The timestamp and filesize of the damaged files were not changed. Only the contents replaced with slices of the logfile. Again, I'm not going to try to 'intentionally' replicate this, so I ask: Has PHP's interface with the NTFS file sub-system ever been reported to splatter a file across the contents of a drive? Is the PHP-interpreter even possible to create something like this? As far as I know PHP utilizes the common OS-syscalls to interact with the filesystem, so it doesn't interact with the harddrive directly, but online with the FS-driver. Did you shutdown the system cleanly, when you recognized this behaviour? If not, it would explain, that the windows assumes the filesystem must be repaired. I can imagine, that this repair process associated the broken data with the wrong file-entries in the fs-table, which could be an explanation for the behaviour you described. Regards, Sebastian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] same php file, different day...worked 3-4 times in the past in the past
2013/1/20 Fred Silsbee fredsils...@yahoo.com Fatal error: Call to undefined function mysqli__connect() in /var/www/html/log_book_MySQLnew_i.php on line 116 There is an underscore _ to much: 'mysqli_connect()' phpinfo.php shows mysqli Additional .ini files parsed /etc/php.d/curl.ini, /etc/php.d/fileinfo.ini, /etc/php.d/json.ini, /etc/php.d/mysql.ini, /etc/php.d/mysqli.ini, /etc/php.d/pdo.ini, /etc/php.d/pdo_mysql.ini, /etc/php.d/pdo_sqlite.ini, /etc/php.d/phar.ini, /etc/php.d/sqlite3.ini, /etc/php.d/zip.ini maybe a mysqli.ini is required containing mysqli.so but [root@localhost php.d]# locate mysqli.so [root@localhostphp.d]# [root@localhost php.d]# locate mysqli /usr/bin/mysqlimport /usr/share/man/man1/mysqlimport.1.gz [root@localhost php.d]# -- github.com/KingCrunch
Re: [PHP] Expansion of Apache definitions
2013/1/10 John Iliffe john.ili...@iliffe.ca I recently made a posting on the Apache users group regarding recovering the client IP address using the $_SESSION['REMOTE_ADDR'] function in PHP. I received the following caveat from another developer: -start quote You may want to update that. Since 2.4, apache makes the distinction between the the two different REMOTE_ADDR candidates: the peer making the TCP connection, and the client making the HTTP request. In other words, the nearest proxy and the end-user. The latter is of course very easy to spoof, but is nevertheless the one most applications want. --end quote Is there any development underway in PHP to have both of these addresses available in the $_SESSION global variable? It's only semi-official, but the whole proxy chain is usually available in X-Forwarded-For. Regards, John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Some date() oddities
Hi, Workaround for what? The 31st of december is the first week of the ISO8601-year 2013. That has nothing to do with PHP, date(), or any warnings somebody left in the comments. Thats the way ISO8601 is defined: http://en.wikipedia.org/wiki/ISO_8601#Week_dates Regards, Sebastian 2013/1/8 Arno Kuhl a...@dotcontent.net I've bumped into an odd result with the date() function that I can't make sense of. Starting with a unix timestamp for 31 December 2012 13:12:12 (which is 1356952332) I calculate a week number: $ux_date = 1356952332; $weeknumber = date(W, $ux_date); // returns 01 instead of 52 I found some warnings regarding ISO8601 for this in the user notes for the date() function in the PHP manual but couldn't see how this is managed in code, does anyone know of a workaround for this? Cheers Arno -- github.com/KingCrunch
Re: [PHP] Boolean type forced on string assignment inside if statement
2013/1/4 tamouse mailing lists tamouse.li...@gmail.com On Fri, Jan 4, 2013 at 1:56 AM, Sebastian Krebs krebs@gmail.com wrote: 2013/1/4 tamouse mailing lists tamouse.li...@gmail.com Bit operators are not comparing values, they're COMBINING values. Technically spoken they're comparing bits, whereas boolean operators does the same, but treaten every value as a single bit. And that's just going to confuse things. Technically speaking, bit operations and NOT logical operations. If you do this: if ($a $b) when you meant this: if ($a $b) it's because you got lucky, not because it's correct. Sorry, but ... well, I don't understand you :X When I want and type it's simply a bug, but sometimes I want , for example like in $a FLAG_ALLOWED, so I don't know, what you are talking about right now -- github.com/KingCrunch
Re: [PHP] Boolean type forced on string assignment inside if statement
2013/1/4 tamouse mailing lists tamouse.li...@gmail.com Bit operators and | are NOT and should NEVER be confused with Logical operators and ||: ?php /** * Bit operators in PHP */ $format = Decimal: %2d Binary: %4b\n; $a = 4; $b = 6; echo Variable \$a:\n; printf($format, $a, $a); echo Variable \$b:\n; printf($format, $b, $b); $c = $a | $b; echo Result of OR bit operator\n; printf($format, $c, $c); $c = $a $b; echo Result of AND bit operator\n; printf($format, $c, $c); ? OUTPUT: --- Variable $a: Decimal: 4 Binary: 100 Variable $b: Decimal: 6 Binary: 110 Result of OR bit operator Decimal: 6 Binary: 110 Result of AND bit operator Decimal: 4 Binary: 100 Bit operators are not comparing values, they're COMBINING values. Technically spoken they're comparing bits, whereas boolean operators does the same, but treaten every value as a single bit. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Noobie starting to learn OOP for databases needs help
2012/12/16 dealTek deal...@gmail.com Hi all, Noobie starting to learn oop for databases from here: https://github.com/JeffreyWay/PHP-MySQL-Database-Class/blob/master/MysqlDb.php I've got lots working but have a few issues: 1 - after an insert I'd like to get the id of the new record and I'm not sure how to get that... mysql_insert_id (depricated?) or mysqli_insert_id() (I am using mySql 5.3) not sure where to add this... (most likely in MysqlDb.php but I don't know where or how...) Instead of true let insert() return the id. And while looking at your code: - You wrote in your DocBlocks, that the methods returns a boolean 0 or 1. Beside that this is wrong (0 or 1 are integers) you return either 'true' or nothing. You should return 'false' as well. - Returning a boolean to indicate the success of a method only makes sense, when not successful is a valid case, but I guess when 'delete()' fail it not be treatened as normal. You should throw an Exception instead. This also includes: It's not required, that a method returns something in every case. If delete() for example doesn't have to tell something, it shouldn't. http://de.php.net/manual/en/function.mysql-insert-id.php 2 - how does one do aggrigate select queries like SELECT SUM(price) FROM mytable ... what I tried seemed to fail... Nothing seems to fail ;) Either it fails, or not (or it just doesn't behave, like expected, what I see as fail too). So what happens? And if anyone can point to some good OOP training URL's I'd appreciate it. Thanks in advance for any assistance... -- Thanks, Dave - DealTek deal...@gmail.com [db-12] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Noobie starting to learn OOP for databases needs help
2012/12/17 dealTek deal...@gmail.com On Dec 16, 2012, at 10:08 AM, Sebastian Krebs krebs@gmail.com wrote: 2012/12/16 dealTek deal...@gmail.com Hi all, Noobie starting to learn oop for databases from here: https://github.com/JeffreyWay/PHP-MySQL-Database-Class/blob/master/MysqlDb.php I've got lots working but have a few issues: 1 - after an insert I'd like to get the id of the new record and I'm not sure how to get that... mysql_insert_id (depricated?) or mysqli_insert_id() (I am using mySql 5.3) not sure where to add this... (most likely in MysqlDb.php but I don't know where or how...) Instead of true let insert() return the id. And while looking at your code: - You wrote in your DocBlocks, that the methods returns a boolean 0 or 1. Beside that this is wrong (0 or 1 are integers) you return either 'true' or nothing. You should return 'false' as well. - Returning a boolean to indicate the success of a method only makes sense, when not successful is a valid case, but I guess when 'delete()' fail it not be treatened as normal. You should throw an Exception instead. This also includes: It's not required, that a method returns something in every case. If delete() for example doesn't have to tell something, it shouldn't. http://de.php.net/manual/en/function.mysql-insert-id.php 2 - how does one do aggrigate select queries like SELECT SUM(price) FROM mytable ... what I tried seemed to fail... Nothing seems to fail ;) Either it fails, or not (or it just doesn't behave, like expected, what I see as fail too). So what happens? Hi Sebastian, Of course you're right well it does fail here... when I try a page with this... $results = $db-query('SELECT SUM(price) FROM tbl_1218'); the error is Fatal error: Problem preparing query in /Users/me/Sites/db/test/sqldb.php on line 281 /** * Method attempts to prepare the SQL query * and throws an error if there was a problem. */ protected function _prepareQuery() { //echo $this-_query; rev this is now fixed with this update if (!$stmt = $this-_mysql-prepare($this-_query)) { trigger_error(Problem preparing query, E_USER_ERROR); --- this is line 281 } return $stmt; } Use mysqli_error() to get the _real_ error. By the way it's better to use exceptions http://php.net/mysqli.error.php http://php.net/mysqli.error-list http://php.net/mysqli.error And if anyone can point to some good OOP training URL's I'd appreciate it. Thanks in advance for any assistance... -- Thanks, Dave - DealTek deal...@gmail.com [db-12] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch -- Thanks, Dave - DealTek deal...@gmail.com [db-12] -- github.com/KingCrunch
Re: [PHP] Compile APC in PHP 5.2
Hi, You should definitely not use PHP5.2 anymore. Regards, Sebastian 2012/12/12 Alexander Diedler adied...@tecracer.de Hello, I try to get APC working for a compiled PHP 5.2.17. On this Ubuntu, we have an PHP 5.3 installed with APT-GET and a PHP 5.2 as CGI module compiled with make etc. In the PHP 5.3 I got APC running in phpinfo, but not in PHP 5.2, what we have to do to get work it? I use this http://de2.php.net/manual/de/install.pecl.static.php but if I use the configure with ./configure --prefix=/opt/php5.2 --with-config-file-path=/opt/php5.2 --with-mysqli --with-mysql --with-pdo-mysql --with-curl --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-freetype-dir=/usr --enable-cli --enable-fastcgi --enable-discard-path --enable-force-cgi-redirect --enable-mbstring --with-bz2 --enable-gd-native-ttf --enable-calendar --with-gmp --enable-bcmath --with-xpm-dir=/usr --enable-soap --with-openssl --with-zlib --with-apc There are only errors in the configure and it seems, that buildconf destroy the configure file. I try also http://www.linuxask.com/questions/how-to-compile-apc-module-for-php but if I add extension=apc.so and restart, it will not be shown in phpinfo. Best regards Alexander -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Unset and __destruct
2012/12/6 Pierre du Plessis pie...@pcservice.co.za Hi all I searched the internet (probably not hard enough), and couldn't find a decent answer. I was wondering why, when calling unset on an object, it doesn't automatically call the __destruct method (if it exists) on the object. Thats because it was never intended :) The engine calls __destruct() right before the GC frees the object, but unset() only decrease the refcount. The next time the GC runs it will call the destructor and everythings fine When unsetting an object, php doesn't automatically remove references to other objects, and you need to manually call the __destruct method where you can remove any references to other objects. Why? When the GC removes the object from the memory (which might be slightly later) it also removes the references to associated objects and when their refcount reaches 0 they will get removed as well. Whats the problem? I know there is a lot of discussion around this topic, but couldn't find a definate answer as to why this isn't the default behaviour. Why should it? Thats the way a GC works :? Any clarification would greatly be appreciated. -- github.com/KingCrunch
Re: [PHP] Session ?
2012/12/7 Jim Giner jim.gi...@albanyhandball.com On 12/7/2012 2:41 PM, Daniel Brown wrote: On Fri, Dec 7, 2012 at 2:38 PM, Jim Giner jim.gi...@albanyhandball.com wrote: On 12/7/2012 2:36 PM, Daniel Brown wrote: On Fri, Dec 7, 2012 at 2:33 PM, Jim Giner jim.gi...@albanyhandball.com wrote: Something new for me - working with scripts on two of my sub-domains. I want to call script 2 in my B domain from script 1 in my A domain. It appears that the session vars established in script 1 do not show up in script 2. Is that because the domain name is different? Is this where one must grab the session id and use it in another script in order to retain the original session and its vars? If this is so, can someone elaborate on the capture of the session id process? Are both domains on the same physical (or virtual) server? Yes - they are sub-domains of my main one. ?php ini_set('session.cookie_**domain','.example.com'); ? The preceding dot before the SLD allow the session cookie to be accessible on *.example.com. What if my sub-domain names are not in the form of 'a.domain.com' and ' b.domain.com'. What do you mean? Subdomains are always in the form *.example.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Session ?
2012/12/7 Daniel Brown danbr...@php.net On Fri, Dec 7, 2012 at 3:04 PM, Jim Giner jim.gi...@albanyhandball.com wrote: OK - now that I've messed us all up, help me to understand your proposed solution. I added the ini-set line to my first script. Then I called my second one and still had the same problem with a missing session var. Is there a corresponding line I need in the 'called' script? And does it matter where this line is place within the script? From your response to Sebastian, I'm not sure it will work. They need to be subdomains of the same domain; different domains won't work. However, proceeding with the presumption that the subdomains are under the same SLD (e.g. - apple.example.com and orange.example.com), this should work: ?php // apple.example.com ini_set('session.cookie_domain','.example.com'); session_start(); $_SESSION['foo'] = 'bar'; session_write_close(); ? Then ?php // orange.example.com ini_set('session.cookie_domain','.example.com'); session_start(); echo isset($_SESSION['foo']) ? $_SESSION['foo'] : 'Session failed to transfer.'; ? Would be better to put 'session.cookie_domain' into the php.ini. In both cases: Clear cookies (at least for your site) completely and set session.auto_start to 0. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Re: shared memory on php servers?
Hi, Why don't you use a database? Seems more appropiate here. At least SQLite should fit ;) Regards, Sebastian 2012/12/4 rene7705 rene7...@gmail.com I would also like to hear any thoughts on how to efficiently add, delete and edit data in this large and deep array structure from multiple sessions at nearly the same time.. On Tue, Dec 4, 2012 at 11:49 AM, rene7705 rene7...@gmail.com wrote: Hi folks.. I'm wondering, what's the fastest way to put a large and deep array() structure in shared memory on a PHP server? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Re: shared memory on php servers?
2012/12/4 Stuart Dallas stu...@3ft9.com On 4 Dec 2012, at 10:51, rene7705 rene7...@gmail.com wrote: I would also like to hear any thoughts on how to efficiently add, delete and edit data in this large and deep array structure from multiple sessions at nearly the same time.. On Tue, Dec 4, 2012 at 11:49 AM, rene7705 rene7...@gmail.com wrote: Hi folks.. I'm wondering, what's the fastest way to put a large and deep array() structure in shared memory on a PHP server? Split the data up into smaller pieces. There's rarely a valid reason to store a huge array of data as a single blob. It's an array, so it breaks up by the first level of keys at the very least. Look at APC, memcached, and redis. These are the most popular ways to store data in shared memory. Note that APC is a PHP extension so you can only access the shared memory from one machine, whereas memcached and redis are separate daemons so you can access them from multiple servers. Also, as Sebastian says, a database is another option unless you have a good reason to want the data in shared memory rather than a DB. Beside that you can have Databases in memory too, like SQLite on a tmpfs-mount, or a specialized memory-persistent database engine :) -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Re: Switch - Case Statement Questions
2012/11/19 Tim Streater t...@clothears.org.uk On 18 Nov 2012 at 14:44, Jim Giner jim.gi...@albanyhandball.com wrote: 2. Using Switch {ALWAYS FIRST CASE!!!} //$boxes = 1; //switch ($count) { //case ($count 14): //$boxes = 3; //break; //case ($count 7 $count = 14): //$boxes = 2; //break; //case ($count = 7): //default : //$boxes = 1; //break; //} To answer Iñigo's comment - the OP's version is very much like an If-ElseIF structure, and nothing like a Switch. Just so. Perhaps those who are not grasping the point could re-read their copy of The Elements of Programming Style by Kernighan and Plauger where this sort of issue is covered. See, it's all about expectations. When I worked at SLAC, there was a wise guy there who had removed the catalytic converter from his Scirocco and who though it clever to race up 280 from San Jose to SLAC at 100mph, sometimes slipstreaming behind another idiot doing the same. If I look in my rear-view mirror, I expect those I can see to be doing 70mph tops (that's what a lot of people did 30 years ago on 280), not 100, and to make judgements accordingly. Equally, I have certain expectations when I see a switch statement; it trying hard to look like if-elseif-etc is not one of them. Just a minor rewrite of the original solution switch (true) { case $count = 7: $boxes = 1; break; case $count = 14: $boxes = 2; break; default: $boxes = 3; break; } Now -- the idea of switch as select on of some similar cases in mind: Is this really breaking any expectation? I think this one is a valid example, when switch(true) doesn't break the semantic of the switch-statement. And if this is already the end of expectations, then (sorry for that) the expectations are maybe slightly limited :X I don't say please use switch(true) wherever possible, but this one is nearly a prototype of a valid use-case: You have several cases all depending on a single state (the variable) and all of the same kind = constant. Beside, because it is so extremely simple example, it can become even more obvious switch (true) { case $count = 7: $boxes = 1; break; case $count = 14: $boxes = 2; break; default: $boxes = 3; break; } Guess some may argue about coding styles now, but thats not the questios here (and anyway: Even coding styles could/should be broken, if it leads to better code. Use it wisely ;)). And now: This _can_ break any expectation? By the way, your car-expectation sounds dangerous... -- Cheers -- Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Re: Switch - Case Statement Questions
2012/11/17 Tim Streater t...@clothears.org.uk On 17 Nov 2012 at 01:33, Iñigo Medina imed...@grosshat.com wrote: On Fri, 16 Nov 2012, Jim Giner wrote: Maybe I'm way out of touch, but when I look at php.net for the syntax of the switch statement I see: switch($var){ case (value): (do something) case (other value): (do something else) } IN your example, you are using a switch syntax that is nothing like that. I think that your case statements are not actually evaluating the value of $count, but are themselves evaluating to a true value that has nothing to do with $count. That `switch` is evaluating to true each case. It's an alternative of using if-elseif structure. It may be an alternative, but it breaks the principle of least surprise. If I'm looking through someone's code, and I see a switch, I expect to see it used as Jim described. If the writer needs a different type of logic to make a decision, that is what the cascaded if-elseif-elseif construct is for, when the tests don't fall into a simple set-of-values choice. But switch(true) is not a surprise by itself, it becomes to, when the cases are surprising. And the given example directly fall into a simple set-of-values choice, but the problem is, that switch(val) by design only covers equality == and thats what this case is: A set like (1) between 1 and 7, (2) between 8 and 14, (Default) greater than 14. On the other side a looong if-elseif*-else-chain is often more confusing and needs refactoring anyway. (Beside: Was the principle of least surprise not a ruby-thing? ;)) The job of a programmer is not to be clever with a view to impress those who follow, but to achieve the desired outcome while at the same time making life easy for those who follow. I don't see a problem in case ($count = 7) or case ($count = 14) or case ($count 14)? I think a developer (or maybe programmer) doesn't need to be very clever to get the idea behind this. -- Cheers -- Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Re: Switch - Case Statement Questions
2012/11/17 Andrew Ballard aball...@gmail.com On Nov 16, 2012 10:24 PM, tamouse mailing lists tamouse.li...@gmail.com wrote: On Fri, Nov 16, 2012 at 12:41 PM, Sebastian Krebs krebs@gmail.com wrote: Beside this it can be rewritten as switch ((int) (($count-1) / 7) { case 0: // 1-7 case 1: // 8 - 14 default: // above 15 } Nice code refactoring :) Just a tad obscure for someone coming along later Not only obscure, but depending on the rule being processed could be plain wrong. It works for the values shown so far, but what if another test is added to the use case in the future that doesn't fit the clever solution? Like so often in our developers world many things breaks, when it comes to new requirements. Without knowing the intent of the code, it could be a headache to maintain. Interesting, that you see 5 lines of code and assume, that nobody will ever get the intent of this code ;) Of course the context is missing. I guess, that $count is something like remaining days, or such, because 7 and 14 look like one week and two weeks, respectively. Thus I wouldn't name the variable $count [1], but $remainingDays and voila: Context is back and so is the intent :) Of course the above code has a quite limited use-case, but that was the requirement (for now, see KISS). If you need more, refactor/rewrite it. [1] Even further: I was taught, that if I ever want to name a variable like count, status, type, ... I should stop and probably don't use this name. In most cases they are used wrong. This example here is quite good: $count what? Just my 2 cents. Andrew -- github.com/KingCrunch
Re: [PHP] Re: Switch - Case Statement Questions
2012/11/16 Tim Streater t...@clothears.org.uk On 16 Nov 2012 at 12:10, Omar Muhsin mrfroa...@gmail.com wrote: Hello, I was just wondering after writting the code in version 2 here below, it turns out in testing that it actually PHP is not validating the expressions instead always I get the first case. 1.Using nested if statement {THE INTENDED BEHAVIOR}: if ($count 14) $boxes = 3; elseif($count 7 $count = 14) You don't need the count=14 part as you will *only* get there if $count=14. $boxes = 2; else $boxes = 1; 2. Using Switch {ALWAYS FIRST CASE!!!} //$boxes = 1; //switch ($count) { //case ($count 14): //$boxes = 3; //break; //case ($count 7 $count = 14): //$boxes = 2; //break; //case ($count = 7): //default : //$boxes = 1; //break; //} Does anyone know the answer why using the Switch it always execute the first case ? As has been pointed out you need switch(true). That's a strange way of writing a switch, IMO. You should be using the if version. Hi, I've seen long discussions about this ;) I think this one is a example, where 'switch(true)' is a legit expression, because switch-statements define a construct, where the interpreter should select one of multiple similar cases. This one seems legit, because they are very similar ;) It says In case of $count look like X do this, or $count look like Y do that, or $count look like Z do something else (and so on). For such I find the if-elseif-elseif-elseif-elseif-else-construction quite confusing. Beside this it can be rewritten as switch ((int) (($count-1) / 7) { case 0: // 1-7 case 1: // 8 - 14 default: // above 15 } Regards, Sebastian -- Cheers -- Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] base64_decode
Am 02.10.2012 19:27, schrieb John Taylor-Johnston: Without anyone infecting their machines, can someone tell me what this is? I found a phishing site on my DreamHost server. DreamHost has been very helpful. We found a file containing this code. What is it? What does it contain? ?php eval(base64_decode('Pz4gPC9kaXY+DQo8ZGl2IGlkPSJmb290ZXIiPjxhIGhyZWY9Imh0dHA6Ly93ZWItaG9zdGluZy1jbGljay5jb20vIiB0aXRsZT0iV2ViIGhvc3RpbmciPldlYiBob3N0aW5nPC9hPg0KPCEtLSAyNyBxdWVyaWVzLiAwLjU2MSBzZWNvbmRzLiAtLT4NCjwvZGl2Pg0KPD9waHAgd3BfZm9vdGVyKCk7ID8+DQo8L2JvZHk+DQo8L2h0bWw+IDw/'));? http://codepad.org/Kyka99fE -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Basic Statistics
Hi, Something like http://php.net/ref.stats ? Regards, Sebastian Am 01.10.2012 18:37, schrieb George R Smith: Can anyone recommend a basic php stat package, easy to install and use. Just basic stuff like mean, median, range std dev etc thanks george -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Static constructor support
2012/9/27 Yves Goergen nospam.l...@unclassified.de On 26.09.2012 23:38 CE(S)T, Stuart Dallas wrote: On 26 Sep 2012, at 22:29, Yves Goergen nospam.l...@unclassified.de wrote: My class is a debug helper class, that can write trace messages and so on. I have added a random per-request tag to distinguish concurrent requests in the trace file and thought that generating such a tag would perfectly fit in a static constructor. Now a helper function does that check and generates one on the first call of the method. I would strongly recommend a singleton, or if you must use a static class you can either use the initialisation mechanism I described or, if the class has a single method as I'm guessing, have that method check the static variable to see if it's been set yet, and if not generate it before doing anything else. Why does everybody seem to recommend singletons so strongly? What's wrong with static classes? Are they considered as global variables, the most evil remainder from the Middle Age? What is easier to call on a regular hacky basis: XyzDebug::Trace(...); or XyzDebug::GetInstance()-Trace(...); Or just XyzDebug\trace(); Functions are not dead yet I really prefer the first one. I always use static classes when there is no real instance of something. Why should I force to act as if, only to follow some trendy pattern? -- Yves Goergen - nospam.l...@unclassified.de - http://unclassified.de -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Static constructor support
2012/9/26 Stuart Dallas stu...@3ft9.com On 26 Sep 2012, at 22:29, Yves Goergen nospam.l...@unclassified.de wrote: On 26.09.2012 23:20 CE(S)T, Stuart Dallas wrote: If you mean what C# calls a static constructor, no that does not exist in PHP, but you can fake it. Okay, thank you for the quick info. How do other languages than C# call that? :-) They generally don't. C# is the only language I've ever come across that support such a thing, and I only found that by accident because it would never occur to me to look for it. In java it's called a static block [1] public class myclass{ static{ //some statements here } } And a use-case is pseudo-constant expression like public class myclass{ public static $CONSTANT; static{ self::$CONSTANT = new DefaultFooBar; } } [1] http://www.erpgreat.com/java/use-of-a-static-block-in-a-class.htm My class is a debug helper class, that can write trace messages and so on. I have added a random per-request tag to distinguish concurrent requests in the trace file and thought that generating such a tag would perfectly fit in a static constructor. Now a helper function does that check and generates one on the first call of the method. I would strongly recommend a singleton, or if you must use a static class you can either use the initialisation mechanism I described or, if the class has a single method as I'm guessing, have that method check the static variable to see if it's been set yet, and if not generate it before doing anything else. -Stuart -- Stuart Dallas 3ft9 Ltd http://3ft9.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] Re: PHP as Application Server
Hi, Once again I didn't read it completely (maybe I will do so), but my 2ct: I recently played with Ruby and Python and of course with their application server (at least a little bit). My experience was, that it is less fun as it sounds in the first place compared to a well designed webserver-interpreter-stack (and of course common OS-specific stuff for CLI). In my eyes it is good the way it is: Let PHP do it's job and let more intelligent tools do the other things, like spawning request-handling processes. Not saying, that I'm against an application, but I currently don't miss it :) On the other side someone must maintain it and someone must make sure, that it is secure and efficient. This resources should not taken from the core-team. Regards, Sebastian 2012/9/27 Alessandro Pellizzari a...@amiran.it Il Thu, 27 Sep 2012 12:28:00 +0200, Maciej Liżewski ha scritto: Sure there are disadvantages and other problems but what Alessando is saying is I would not use cure for cancer even if it existed because it can introduce other problems like overpopulation. Uhm, no. I see it as I would not use chemio if I could remove the cancer with laser therapy. They are two ways to solve the same problem, and I think the non- application-server way is the best. It is similar to the Unix way: many small pieces tied together to reach a goal. The application server is more like the Windows way: one big piece to reach a goal. I understand sometimes the application server can be easier or fit better, but I think most of the times it is the wrong solution, expecially in PHP, but not exclusively. Bye. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- github.com/KingCrunch
Re: [PHP] about PHP's filter_var function
Am 20.09.2012 19:54, schrieb Jim Lucas: On 09/20/2012 10:00 AM, Matijn Woudt wrote: On Thu, Sep 20, 2012 at 6:03 PM, Jim Lucasli...@cmsws.com wrote: On 09/20/2012 02:35 AM, Sebastian Krebs wrote: Plaseplease update... 5.1.6 is from 2006! I read the it's required, but I can't imagine _anything_ that it's worth it to use such an extremely outdated, unsupported and therefore insecure and inefficient version... You know: There are 3 (!) new minor versions available right now (5.2, 5.3 and 5.4). However: Regarding your concrete problem I guess you can use ip2long() if (ip2long($ip)) { I would suggest a modification to this. if ( ip2long($ip) !== false ) { I suggest this because IP to long will return negative numbers for half the IP range. Therefor 50% of your possible results would be considered false when in fact they are valid IPs. See Example #2 on this page: http://php.net/manual/en/function.ip2long.php First of all, I agree with Maciek that inet_pton is the way to go because of IPv6. But, there seems to be some wrong information in your reply which bothers me. First of all, ip2long only returns negative numbers on 32bit systems, not on 64bit (which most servers are nowadays). Second, there's nothing wrong with the if, if(-5) is still true. The only difference is that you can differentiate between IP 0.0.0.0 and false. But IP 0.0.0.0 is not valid anyway. - Matijn After some testing, I stand corrected. Wow, I wonder where I ran into the issue of negative numbers equating to false. while loops maybe... Strange. I must have ran into this issue years ago. I have always performed strict (===) comparisons because I thought PHP would equate negative numbers as false. Learn something new every day... You can find the full matrix here: http://php.net/types.comparisons -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] about PHP's filter_var function
Plaseplease update... 5.1.6 is from 2006! I read the it's required, but I can't imagine _anything_ that it's worth it to use such an extremely outdated, unsupported and therefore insecure and inefficient version... You know: There are 3 (!) new minor versions available right now (5.2, 5.3 and 5.4). However: Regarding your concrete problem I guess you can use ip2long() if (ip2long($ip)) { } else { } Regards, Sebastian Am 20.09.2012 11:14, schrieb lx: Hello: I want to use filter_var function by this way: $ip = 192.168.0.1; if( !filter_var($ip, FILTER_VALIDATE_IP) ) { echo IP is not valid; } else { echo IP is valid; } I want to check the string $ip is IP address or not.but my PHP version is 5.1.6. and I know the filter_var requires at least PHP version 5.2.0. so, Any other function in PHP 5.1.6 can slove this work and replace the filter_var function ? Thank you, I'm a new one, so I don't know much about PHP documentation. By the way, The PHP version is required. so I can't upgrade it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] about PHP's filter_var function
Am 20.09.2012 18:03, schrieb Jim Lucas: On 09/20/2012 02:35 AM, Sebastian Krebs wrote: Plaseplease update... 5.1.6 is from 2006! I read the it's required, but I can't imagine _anything_ that it's worth it to use such an extremely outdated, unsupported and therefore insecure and inefficient version... You know: There are 3 (!) new minor versions available right now (5.2, 5.3 and 5.4). However: Regarding your concrete problem I guess you can use ip2long() if (ip2long($ip)) { I would suggest a modification to this. if ( ip2long($ip) !== false ) { I suggest this because IP to long will return negative numbers for half the IP range. Therefor 50% of your possible results would be considered false when in fact they are valid IPs. See Example #2 on this page: http://php.net/manual/en/function.ip2long.php No, negative numbers are true too. Only 0 is false, so '0.0.0.0' is the only edge case. } else { } Regards, Sebastian Am 20.09.2012 11:14, schrieb lx: Hello: I want to use filter_var function by this way: $ip = 192.168.0.1; if( !filter_var($ip, FILTER_VALIDATE_IP) ) { echo IP is not valid; } else { echo IP is valid; } I want to check the string $ip is IP address or not.but my PHP version is 5.1.6. and I know the filter_var requires at least PHP version 5.2.0. so, Any other function in PHP 5.1.6 can slove this work and replace the filter_var function ? Thank you, I'm a new one, so I don't know much about PHP documentation. By the way, The PHP version is required. so I can't upgrade it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] about PHP's filter_var function
Am 20.09.2012 18:17, schrieb Maciek Sokolewicz: On 20-09-2012 18:03, Jim Lucas wrote: On 09/20/2012 02:35 AM, Sebastian Krebs wrote: Plaseplease update... 5.1.6 is from 2006! I read the it's required, but I can't imagine _anything_ that it's worth it to use such an extremely outdated, unsupported and therefore insecure and inefficient version... You know: There are 3 (!) new minor versions available right now (5.2, 5.3 and 5.4). However: Regarding your concrete problem I guess you can use ip2long() if (ip2long($ip)) { I would suggest a modification to this. if ( ip2long($ip) !== false ) { I would actually suggest using inet_pton() instead of ip2long, since it can also handle IPv6 adresses, not only v4 which people here seem to think are the only ones in use on this planet. And I agree with Jim that you really should use a strict equality check in this case. IPv6 is a valid point, but inet_pton() triggers a warning in case of invalid addresses, which makes it quite useless for validation in my eyes. Also it's not available on windows before 5.3 And the strict comparison feels ... a little bit to much. Of course depending on the use-case, I would treat 0.0.0.0 as invalid too. - Tul -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP array unions
Hi, In PHP the array is in fact a hash map, but especially it is _used_ for nearly everything map-, set-, ...-like thing. So in short: The is no operator or built-in function, that merges two arrays _and_ treat them as set (instead of the hashmap, what they are). Your solution is the way to go. Regards, Sebastian Am 12.09.2012 17:10, schrieb Adam Richardson: Hi! So, PHP has the '+' array operator, which forms the union of arrays, but it does so by key. What I'm looking for is a function that forms the union of arrays based on value. Currently, I use code like the following: array_unique(array_merge($array1, $array2, $array3)); This is useful to me because I tend to program using functional programming principles. Just want to make sure I'm not missing a core function that already does this. If there's not a core function, I might just build an array_union extension because the functionality is so common in my codebases. Thanks, Adam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] away from Fedora linux for a while and now this ...HELP
Am 25.08.2012 13:04, schrieb Matijn Woudt: On Sat, Aug 25, 2012 at 1:54 AM, Sebastian Krebs krebs@gmail.com wrote: Am 25.08.2012 01:41, schrieb Fred Silsbee: Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Fatal error: Unknown: Failed opening required '/var/www/html/log_book_MySQL.php' (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0 had to use Fedora yumex(yum) to install php PHP Version 5.4.5 is seen in phpinfo before now, php was there and ready after Fedora install Hi, I guess you created the file yourself (with your user account) and want to watch it within your browser via your webserver? The last one usually runs under the www-data:www-data (debian. Guess Fedora takes it similar) user:group. So, either change the owner, or change the permissions. An example | chmod g+rw /var/www/html/log_book_MySQL.php | chown www-data:www-data /var/www/html/log_book_MySQL.php and add yourself to the group www-data. Don't know, how it can be done in Fedora. Debian uses usermod, but as far as I know it's a debian tool(?). Regards, Sebastian I don't use Fedora, but I doubt that would be necessary. All files created by a user account have read rights for world, atleast on all the Unix servers/PCs I maintain. This depends on the umask. One may come to the conclusion to secure a system by setting a more restrictive umask (which is at all not that bad idea) and then some days/weeks/months later he realizes, that something stoped working. Changing the umask is useful, if you have many different users and you want them to be more separated from each others. Maybe it's just a typo? Linux is case sensitive, so make sure the file is really called log_book_MySQL.php, and not log_book_MYSQL.php for example.. Good point too :D - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A quick ereg translation
Am 25.08.2012 23:06, schrieb Lester Caine: ereg('body(.*)/body', $phpinfo, $regs); Pulls the body of phpinfo() to use with a tidy header of other system information, but I'm struggling to get a pcre alternative. Anybody already cracked this one? usually it's just fine to wrap the pattern into delimiter. | preg_match('~body(.*)/body~i', $phpinfo, $regs); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] away from Fedora linux for a while and now this ...HELP
Am 25.08.2012 01:41, schrieb Fred Silsbee: Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0 Fatal error: Unknown: Failed opening required '/var/www/html/log_book_MySQL.php' (include_path='.:/usr/share/pear:/usr/share/php') in Unknown on line 0 had to use Fedora yumex(yum) to install php PHP Version 5.4.5 is seen in phpinfo before now, php was there and ready after Fedora install Hi, I guess you created the file yourself (with your user account) and want to watch it within your browser via your webserver? The last one usually runs under the www-data:www-data (debian. Guess Fedora takes it similar) user:group. So, either change the owner, or change the permissions. An example | chmod g+rw /var/www/html/log_book_MySQL.php | chown www-data:www-data /var/www/html/log_book_MySQL.php and add yourself to the group www-data. Don't know, how it can be done in Fedora. Debian uses usermod, but as far as I know it's a debian tool(?). Regards, Sebastian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Cost of redirect and site domain switch? Good Practice/ Bad Practice / Terrible Practice
2012/8/20 Jim Giner jim.gi...@albanyhandball.com On 8/20/2012 12:19 AM, Jim Lucas wrote: On 8/17/2012 6:35 PM, Jim Giner wrote: On 8/17/2012 7:16 PM, Jim Lucas wrote: You could simply remove all full domain+path URL links and replace them with absolute path urls only. turn http://www.somedomain.com/**path/to/my/webpage.htmlhttp://www.somedomain.com/path/to/my/webpage.html into /path/to/my/webpage.html This would work with either domain. Those would be relative paths, ..o? No. Quick Google search turns up this: http://www.uvsc.edu/disted/**decourses/dgm/2120/IN/steinja/** lessons/06/06_04.htmlhttp://www.uvsc.edu/disted/decourses/dgm/2120/IN/steinja/lessons/06/06_04.html I have three description or types of paths that I use normally. I feel the first two generally get grouped together by most persons. Full or complete path: a href=http://www.cmsws.com/**index.phphttp://www.cmsws.com/index.php Home/a Absolute Path: a href=/index.phpHome/a Relative: a href=index.phpHome/a -- Jim Lucas http://cmsws.com Anything that does not absolutely define something, is relative to the current context. In this case since your href does not mention the sitename, in my book that equates to something relative. absolute path != absolute (or better full-qualified) URL/URI. Therefore /foo/bar is an absolute path, but a relative URI. Count me as one person who would never lump the first two ex. into one. The simple device of using the leading slash to start the href indicates its relativity to the the home folder of the site. The document-root. The home of the user the webserver/interpreter is running on may be somewhere else. The lack of a leading slash indicates its relativity to the current folder. Relative to the current path. Especially with rewrites folder and path can be completely different.
Re: [PHP] Cost of redirect and site domain switch? Good Practice / Bad Practice / Terrible Practice
If you need to change the domain completely, choose 301. - Crawler will recognize it and will update their indexes quite soon. Especially you avoid duplicate content-punishments, because you say yourself, that the content originally comes from another domain, that isn't anymore (Like It's not a duplicate, it's _the_ content, but under a different address). - The delay is negliable. Also as soon as every index were updated no new visitor should enter your site via the old domain. Browser should (don't know wether they do, or not) recognize 301 too and redirect any further request to the url on their own (think of it as they cache the redirect permanently). If this change is only temporary I would recommend using 307 to avoid duplicate contents. I would even say, that a 307-redirect from somenewdomain.com to somedomain.com is more appropiate, but that depends. Regards, Sebastian Am 17.08.2012 21:35, schrieb Tristan: So, I need to change from somedomain.com to somenewdomain.com I was thinking of doing this 1) create an alias to the site somenewdomain.com to point to current server 2) run permanent 301 redirect from somedomain.com to somenewdomain.com I was thinking this was a clean safe way to do it so we dont have to run a global find replace. Concerns might be but, I don't know for sure? 1) SEO 2) processing / time / cost for the 301 redirect on any old somedomain.comrequests What do you guys think? Thanks, T -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Two ways to obtain an object property
Hi, 2012/8/15 phplist phpl...@myword.co.uk This relates to a minor dilemma I come across from time and time, and I'm looking for advice on pros and cons and best practice. Last night I encountered it again. Within a site I have a User object, and within page code would like to have if ($crntUser-isASubscriber) {...} There seems to be two ways to handle this: I can have a User object method getSubscriberStatus() which sets $this-isASubscriber. But to use this I would have to run the method just before the if statement. Or I could have a method isASubscriber() which returns the result, meaning the if statement should be if ($crntUser-isASubscriber()) {...} or you just set User::$isASubscriber before. or you can utilise __get() I don't really get the problem. You can for example set the property right after instanciation, or during instanciation (constructor). $this-isASubscriber = !empty($subscriptions); // or something like that Regards, Sebastian While this is last night's specific example, I seem to face the method-setting-variable or the method-returning-result-**directly decision quite often. Is either of these approaches preferable, or does it simply not matter? Thanks Roddie Grant -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP Stats
Hi, http://w3techs.com/technologies/details/pl-php/all/all For example. Click around, nice stats there. Regards, Sebastian Am 31.07.2012 20:31, schrieb Tedd Sperling: Hi gang: Do we have anything a bit more up to date than this? http://php.net/usage.php That's five years out of date! Also, the links out don't really provide anything useful -- they are either dated, show vested interest (i.e., want money), or they provide information not relevant to php. For example, Objective C overtakes C++ I find interesting, but it doesn't relate to PHP. As such, I have a difficult time figuring out what web languages are the most wide-spread. So, do we have something better? Cheers, tedd _ t...@sperling.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex
Hi, Am 27.07.2012 19:07, schrieb Ethan Rosenberg: Dear list - I've tried everything and am still stuck. A regex that will accept numbers, letters, comma, period and no other characters This? /^[0-9a-zA-Z,.]$/ Regards, Sebastian Thanks. Ethan Rosenberg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Regex
Am 27.07.2012 19:54, schrieb shiplu: #[0-9a-zA-Z,\.]# You should escape out that period as it will match any character otherwise. Thanks, Ash Ash, Thats not true. In character class only meta-characters are \ ^ - [ And the dash only when it's not the first, or the last in the class. and ]. This is the rule of PCRE (see http://www.pcre.org/pcre.txthttp://www.pcre.org/pcre.txt#CHARACTERS%20AND%20METACHARACTERS). I assume we are talking about pcre as everybody used delimiter here which is required in pcre. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] E_STRICT safe PEAR
Hi, I'm using Ubuntu, but here you can update the system packages with the pear executable too $ sudo pear update-channels sudo pear upgrade --alldeps Regards, Sebastian Am 24.07.2012 17:05, schrieb Lester Caine: Not sure the best place to ask this ... I've worked through all of my own codebase to eliminate E_STRICT warnings/errors and now I'm working on the more basic ones coming from PEAR such as PHP Strict Standards: Non-static method PEAR::isError() should not be called statically Since these are installed by the distribution, in my case SUSE12.1, is there a better version to download that is E_STRICT clean? Or o I h2ve to work through that as well for the modules that the third party libraries are picking up? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] E_STRICT safe PEAR
Am 24.07.2012 18:46, schrieb Lester Caine: Sebastian Krebs wrote: Hi, I'm using Ubuntu, but here you can update the system packages with the pear executable too $ sudo pear update-channels sudo pear upgrade --alldeps The question is - Is the result E_STRICT safe? Would say: Depends on the package you use. I don't use PEAR-packages myself, thus I don't really know. I would say: Try it out :) Test it on your dev-machine, or within a vm and nothing can break. I've got what I think is the latest from SUSE12.1 but with PHP5.4 I have to disable E_STRICT again in order to use anything from it ... Regards, Sebastian Am 24.07.2012 17:05, schrieb Lester Caine: Not sure the best place to ask this ... I've worked through all of my own codebase to eliminate E_STRICT warnings/errors and now I'm working on the more basic ones coming from PEAR such as PHP Strict Standards: Non-static method PEAR::isError() should not be called statically Since these are installed by the distribution, in my case SUSE12.1, is there a better version to download that is E_STRICT clean? Or o I h2ve to work through that as well for the modules that the third party libraries are picking up? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] E_STRICT safe PEAR
Am 24.07.2012 22:41, schrieb Lester Caine: Sebastian Krebs wrote: The question is - Is the result E_STRICT safe? Would say: Depends on the package you use. I don't use PEAR-packages myself, thus I don't really know. I would say: Try it out :) Test it on your dev-machine, or within a vm and nothing can break. Sebastian I'm asking because what I have, which I think is the latest version of PEAR, is throwing numerous E_STRICT errors! Didn't you say you use the builtin packages from suse? I guess they are _not_ the latest :X I'm trying to establish if this is actually correct, and that PEAR has never been brought up to date, or I'm still hitting a pre E_STRICT version. As mentioned: That depends on the packages. There are packages, that are completely unmaintained nowadays. However, I have some tools, that relies on PEAR-packages and I've seen no E_STRICT for a while now, which makes me think, that at least some, if not all, are PHP5.4-compliant. I suspect the former which is not very helpful when I've been told simply to fix my own E_STRICT problems ... I don't have time to rework PEAR as well as the libraries I've already fixed :( So is E_STRICT simply something that should be thrown in the bin and the defaulting ON in PHP5.4 is somewhat premature? On my dev machine I use the same settings and it works well (I use Ubuntu, but I cannot imagine, that this makes such a huge difference). Did you try this in the meantime? (Replace sudo with the execute as root suse uses ;)) $ sudo pear update-channels $ sudo pear upgrade pear $ sudo pear update-channels $ sudo pear updrade --alldeps Don't know, if 'update-channels' twice is really required, but it's doesn't hurt and I have the pear installer in mind with some curious behaviours ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] magic getter
Hi all, is this a bug, or a feature? class Foo { private $data; public function __get($name) { return $this-data[$name]; } } $foo = new Foo(); $foo-color = 'red'; echo $foo-color; I would expect an error, or a least a notice, but it prints out red ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] magic getter
Hi all, is this a bug, or a feature? class Foo { private $data; public function __get($name) { return $this-data[$name]; } } $foo = new Foo(); $foo-color = 'red'; echo $foo-color; I would expect an error, or a least a notice, but it prints out red ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Bazar behavior w/ private member variables
Should go to the mailinlist : -- Forwarded message -- From: Sebastian Krebs krebs@gmail.com Date: 2012/7/13 Subject: Re: [PHP] Bazar behavior w/ private member variables To: Nathan Nobbe quickshif...@gmail.com Hi, Private properties are only accessable from within an object of the class, where it's defined. If you define a new private property with the same name in a subclass, then you just have two properties with the same name, but in different classes. They are separate from each other ;) It seems, that you are _really_ looking for protected properties instead. Regards, Sebastian 2012/7/13 Nathan Nobbe quickshif...@gmail.com On Thu, Jul 12, 2012 at 9:23 PM, Nathan Nobbe quickshif...@gmail.com wrote: On Thu, Jul 12, 2012 at 8:38 PM, Tommy Pham tommy...@gmail.com wrote: On Thu, Jul 12, 2012 at 7:19 PM, Nathan Nobbe quickshif...@gmail.com wrote: Hi all, Strangely PHP seems to let each class have its own layer of private scope for member variables. If a subclass defines a member variable of the same name as one defined in the parent the values are maintained independently in instances of the child class. First off a simple class with a private member variable $_myPrivate, and a public accessor method which returns its value: class A { private $_myPrivate = 5; public function getMyPrivate() { return $this-_myPrivate; } } Second, a subclass, that gets weird right away, first we define a private member variable that already has been defined in the parent class, and give it a different initial value. To illustrate the behavior we have two accessor methods, setMyPrivate that uses the $this keyword to get the value of $_myPrivate, which returns the value of the subclasse's version of the variable, and getParentsMyPrivate, that calls A::getMyPrivate via the parent keyword and it returns the value of $_myPrivate as defined in the base class. class B extends A { private $_myPrivate = 6; public function setMyPrivate() { $this-_myPrivate = 6; } public function getMyPrivate() { return $this-_myPrivate; } public function getParentsMyPrivate() { return parent::getMyPrivate(); } } Look at a var_dump of an instance of B: object(B)#2 (2) { [_myPrivate:B:private]= int(6) [_myPrivate:A:private]= int(5) } clearly storage is allocated for two different values. Now I'm sure you all know that if I were to define a private method in A and try to call it from B a Fatal error is raised, something on the order of PHP Fatal error: Call to private method A::tryToCallMeFromB() from context 'B' so why the special treatment for member variables, is this supposed to be a feature? -nathan That is OOP accross all languages. If you want the child class to modify the variable, then set it to protected. Private is only accessible within that class. I know that sounds like it should make sense but if it's true, it's an aspect I've never known about, at least maybe I'm just spacing really bad or something... Anyway, this chokes in javac: public class PrivateAccess { private Boolean isAccessible = true; } class PrivateAccessChild extends PrivateAccess { public Boolean getAccessible() { return isAccessible; } } PrivateAccessChild.java:5: isAccessible has private access in PrivateAccess return isAccessible; ^ -nathan Ahhh, but if I add the private declaration in the subclass it works. Where have I been?? -nathan
Re: [PHP] Contribute to PHP
Hi, Nowadays contributing to an OSS-project is (thankfully) often just a matter of creating a github account and sending a pull request. Because you mentioned the ZF, have a look at it's github mirror [1]. There is also a section about contributing in the readme-file. Other projects have similar documents. Regards, Sebastian [1] https://github.com/zendframework/zf2/ 2012/7/12 Ziad Jammal z...@eljammal.com Deal all phpiers, It took me a while before I hit the send key. I have been a php developer for some time and I got certified beginning of this year. I have always wanted to start contributing to php and zend framework, but I am unable to find the right docs, examples, and the how. I know it might be a simple task, but I appreciate your support as I really want to contribute some good stuff to the php community. Appreciate if someone can share a reported bug, how he traced its location and how he got it fixed. Many thanks, Ziad -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Is this list less busy than it used to be?
Hi, Just realize, that this is _not_ the internals list. :X There I only read. Yes, I could send mails here :) We'll see My guess: The ecosystem has grown. Now much stuff, that were former (probably) asked here, is gone to more specific lists, like ZFs, Symfony, and so on. Maybe it's even already solveable via Twitter ;) Regards, Sebastian 2012/7/4 Andy McKenzie amckenz...@gmail.com On Wed, Jul 4, 2012 at 6:04 AM, RGraph.net support supp...@rgraph.net wrote: Hi, https://docs.google.com/spreadsheet/ccc?key=0Ak1QF0ijPYbedDNvb19SQl80MHcxUWhhbTZOYm5FUlE Yikes. That's a littled bit worrying. Or does it really mean that everyone is getting much better with PHP? :-) -- Richard, RGraph.net support RGraph: JavaScript charts for your website http://www.rgraph.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php My guess would be that it's just one of those things -- every list I've ever been on goes through cycles of more and less activity. Also, most of them wind down quite a lot in the North American summer (the motorcycle forums being an exception). They also tend to hit a peak around the end of the first/beginning of the second year they exist, then taper off for a while, then come back. I'd bet when the next major version of PHP is released we'll see an upswing in traffic for a while as people try to figure it out. -Andy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Searching IDE.
Hi, 2012/6/13 David Arroyo darr...@gmail.com Hi Folks, I am searching an IDE for php and web development, my options are Aptana or Eclipse+PDT. What is your opinion? PhpStorm Thanks. Regards. -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: Function size
Hi, Just want to throw my 2 cent in :) 2012/5/30 Tony Marston t...@marston-home.demon.co.uk Ashley Sheridan a...@ashleysheridan.co.uk wrote in message news:1338326229.2616.31.camel@localhost.localdomain... On Tue, 2012-05-29 at 17:06 -0400, Paul M Foster wrote: On Tue, May 29, 2012 at 08:52:46AM +0100, Tony Marston wrote: On May 21, 2012, at 8:32 PM, tamouse mailing lists wrote: A rule of thumb is no more than 50 lines per function, most much less. Back in the day when we didn't have nifty gui screens and an 24 line terminals (yay green on black!), if a function exceeded one printed page, it was deemed too long and marked for refactoring. I think the idea of setting an arbitrary limit on the number of lines that a function should contain is quite ludicrous and something which I will completely ignore. If a function requires a hundred or more lines then so be it. The only reason to take a block of code and put it into its own function is when that code is likely to be called more than once so that it conforms to the DRY principle. If it is only ever used in one place then there is no point. The problems I have with creating lots of small used-only-once functions is as follows: - you have to create a meaningful name for each function. - all those functions should be arranged in alphabetical order within their containing file - having them in a random sequence makes it difficult to find the one you want. snip And yeah, alphabetical order? Really? This is a throwback to my 3GL days when all components within a file were arranged in alphabetical sequence so that they were easier to find when you looked at the printed listing. Group them by similarity, sure. But today, with IDEs that will jump straight to functions and class methods, and the good ol' find tool on every editor I've ever seen, is sorting them alphabetically really necessary? Seems like a waste of time that is likely not going to be done by fellow developers working on the same codebase. I have never come across an IDE that jumps to a function when you click on its name, so how does it return to where you jumped from? At least PhpStorm and Eclipse have a feature to return where you come from. I haven't seen an IDE, that is _not_ able to jump to a functions or methods source for a long time now. Rather than artificially reduce the size of a function to satisfy someone else's limited attention span I would rather use the scroll wheel on my mouse. Scrolling up or down within a single function is easier than searching/finding/jumping to a series of sub-functions which may exist at random locations within the same file. If the functions were named properly you don't have to follow every execution path to the deepest deep. Or do you reading PHPs C-source, just because a wild substr() appeared? When you see a method loadFromFile() and the IDE tells you, that it expects a $filename as parameter, why should you jump there just to make sure, that the method loads something from a file by the filename given as first parameter? I will only split a large function into sub-functions when it makes sense to do so, and not because some nerd cannot scan more than 20 lines at a time. The question I ask myself is: Why ^should^ a scan more than 20 lines at a time, if it is possible, to make it clearer, but another nerd decided, that it is too much work (or whatever). Maybe it's may attention span, but I'm usually slightly bugged, when I have to read code monsters. Compared to a book it's a kind of One chapter in a single sentence. Regards, Sebastian -- Tony Marston http://www.tonymarston.net http://www.radicore.org -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Unit Tests for Cache Class
Hi all, I'm just writing a small cache class to optimize my database connection. I want to use three different stages to store and receive my data as fast as possible. 1) fast get data from class variable if existing 2) mid get data from memcache if existing - save result as class variable 3) slowest: sql query - receive data from database - save result to memcache - save result as class variable How would you write (unit) tests for such a class? What is the best way to prove, that all data was stored correctly, even after data manipulations like insert/update/delete? I'm looking forward to your suggestions, Sebastian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Singleton with variable parameters
Hi guys, I am trying to generate an abstract Singleton class for use in arbitrary classes, like class Foo extends Singleton {} and generate a new class with Foo - getInstance(); How can I manage to use this with an unkown number of parameters like Foo - getInstance('a', 'b'); ? Something like self::$instance = call_user_func (array(static , __construct), func_get_args()); instead of self::$instance = new self; doesn't work and an eval() is too slow. I hope you can help me. Thanks, Sebastian class Singleton { static private $instance = null; static public function getInstance() { if http://www.phpbar.de/w/if(null === self::$instance) { self::$instance = new self; } return http://www.phpbar.de/w/returnself::$instance; } private function __construct(){} private function __clone(){} }
[PHP] Model View Concepts
Hi all, I'm currently searching for any code snippets, tutorials, howtos, concepts which explain different ways to collect all type of data/input (i.e. inside a class, xml, json string whatever) and create independent html files (i.e. different designs), xml files, pdf files, etc. out of that pool of data. Do you have any urls or own experience you could share? Thanks, Sebastian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Unicode - Entitiy Encoding
Hi all, I'm stuck with this problem: I am trying to convert a text with any kind of unicode characters to its octet and entity equivalents. For example: Ë is #203; as octet and Euml; as entity Đ is #272; as octet and Dstrok; as entity My code works fine for some characters ( Ë works fine, but Đ fails at entity encoding). Do you have a hint, how to solve this? I try to get the octet encoding with mb_encode_numericentity which works fine for everything $convmap = array( 0x22, 0x22, 0, 0x, # 0x26, 0x27, 0, 0x, # ' 0x3c, 0x3c, 0, 0x, # 0x3d, 0x3d, 0, 0x, # 0x80, 0x, 0, 0x, ); $oct_string = mb_encode_numericentity($test, $convmap, 'UTF-8'); I try to get all entity encodings with htmlentities $entity_string = htmlentities($test, ENT_QUOTES, 'UTF-8'); But that fails for some characters like Đ. Is there a better way to get all entity encodings? Thanks, Sebastian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Execute a php page and don't wait for it to finish
Ferdi schrieb: Hi List, I have a php page that updates data from one database to another when it is run. My query is, how can I trigger the execution of this update page from another php / javascript without the calling page having to wait for the update page to finish? Basically, I think the update page needs to use: ignore_user_abort(1); set_time_limit(0); // I don't think the script will take more than 1 min. At the other end I found this: 1) http://www.mindraven.com/blog/php/run-a-php-script-in-the-background-using-ajax/ 2) On that page a user suggested using *pclose(popen(‘/usr/bin/php /path/to/something.php /dev/null ’, ‘r’)* **However, I need this to be usable on windows servers also. 3) Finally, would pcntl_exec, pcntl_fork, exec or something be useful for me? Which of the above 3 options is the better one? Other suggestions are welcome :) Thanks and Regards, Ferdi 1) I guess an asynchronous ajax request is what you are looking for. But it won't work on command line. 2) Maybe http://robert.accettura.com/blog/2006/09/14/asynchronous-processing-with-php/ could help you, but I never tried that. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Firs Day Of Week UNIX
Don Wieland schrieb: Hi gang, I need a bailout. I have a fields called sys_first_day_of_week and the user can select one value which will be from a menu with these options: Monday Tuesday Wednesday Thursday Friday Saturday Sunday Based on this Preference and TODAYS DATE, I want to calculate the first day of the week. So if my preference is Monday and Today's date is 10/19/2010, I want to return a value of: 1287374400 (which is 10/18/2010) if my preference is Wednesday and Today's date is 10/19/2010, I want to return a value of: 1286942400 (which is 10/13/2010) Appreciate any help. Don I'm not sure: You are searching the date of the last given weekdate? $sys_first_day_of_week: Monday = 1, ..., Saturday = 6, Sunday = 0 Try this one: date seems to be correct, but value is different, maybe different time zone? if ( date('w') $sys_first_day_of_week ) { $value = mktime(0,0,0,date('n'),date('j'),date('Y')) - ( 7 + date('w') - $sys_first_day_of_week ) * 24 * 60 * 60; } else { $value = mktime(0,0,0,date('n'),date('j'),date('Y')) - ( date('w') - $sys_first_day_of_week ) * 24 * 60 * 60; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] References in Sessions
Alexander Schrijver schrieb: Is my message unclear? or didn't anyone ran into this problem? If you want an atomic solution, you need to save the session to your database. How often do you need to delete data? Isn't it better to delete at night when noone is online, or logout all users for some minutes while deleting? In addition to that I don't understand, why it is important to prevent deletion if a point is selected ... If you want to work with something that was deleted, print an error and that's it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php