Re: [PHP] Quick Poll: PHP 4 / 5
- Original Message - From: "Jasper Bryant-Greene" <[EMAIL PROTECTED]> To: Sent: Friday, September 16, 2005 4:45 PM Subject: Re: [PHP] Quick Poll: PHP 4 / 5 Stephen Leaf wrote: So yes a bug. But for those that want to be able to grab only what we need. in my case array_pop's returned element. I don't wanna be hassled with the "are you sure you wanted to ignore part of what we did?" It's almost like every program asking "are you sure you wanted to close me?" everytime I get asked that I always think... "I did just click the X.. so Yah..." But why use array_pop() to get the last element, when you know it's intended to shorten its passed array as well? I mean, sure, it might take a few more lines of code to do it properly, but it has the advantage that whoever has to look at the code next might actually understand what's going on in your head. $array = explode( ',', $some_string ); $last_element_pos = count( $array ) - 1; $last_element = $array[$last_element_pos]; [ sure, you could put the count( $array ) - 1 as the array subscript but I was just extending it out for illustration... it's probably easier to understand later on anyway. ] Actually I choose array_pop for 2 reasons. I like short code. I don't want to read thousands of lines just to get an idea. I tend to think in very compact code. if you find that ugly and unreadable. that's your preference. I find extended coding very ugly, mostly because I'm a slow reader, and that is my preference I got use to working with pop and shift while I was doing perl work. so to me pop'ing an array makes perfect sense. -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] xml first special char
- Original Message - From: "Joerg P" <[EMAIL PROTECTED]> To: Sent: Friday, September 16, 2005 2:07 PM Subject: [PHP] xml first special char hello, I have some words with german special chars in mysql. When I print those strings direct as xml to the browser, everything seems fine. But there is one 'ä' that makes me crazy. It always appears as a ? in Firefox and even makes an error in ie. But other 'ä's are ok. What could I do? Joerg have you tried changing the encoding in firefox to see if it fixes the ? If that works try enforceing that encoding. Either with a header(); and/or I use this function to set the header information in most if not all of my websites You can safely ignore the $this->outXML I use that because I mainly work with XSL documents. appending a ?xml to some of my sites will give you the raw XML perfect for debugging purposes. :) function outputHeader($docType='', $filename=null) { if (!$this->outXML) { header("Content-Type: text/html; charset=utf-8"); echo ''."\n"; echo ($docType != '')? $docType: '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";>'."\n"; } elseif ($this->outXML) { header("Content-Type: text/xml; charset=utf-8"); } else { header("Content-Type: $docType; charset=utf-8"); if (!empty($filename)) { header('Content-Disposition: attachment; filename="'.$filename.'"'); } if ($docType=="text/xml") { echo 'encoding="utf-8"?>'."\n"; } } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Quick Poll: PHP 4 / 5
- Original Message - From: "Jasper Bryant-Greene" <[EMAIL PROTECTED]> To: Sent: Friday, September 16, 2005 11:14 PM Subject: Re: [PHP] Quick Poll: PHP 4 / 5 leaf wrote: Actually I choose array_pop for 2 reasons. I like short code. I don't want to read thousands of lines just to get an idea. I tend to think in very compact code. if you find that ugly and unreadable. that's your preference. I find extended coding very ugly, mostly because I'm a slow reader, and that is my preference And what about someone else that has to read/maintain your code in the future? What about when you come to read a "clever" but compact line of code that does 5 or 6 things on a single line, a few years down the track, and spend valuable time just trying to figure out what it actually does? I think in compact code. so reading it back is not a problem. As for future programmers who want to look at my code? That's never happened so far. However I do keep good documentation. so reading and understanding my code shouldn't be a problem. I got use to working with pop and shift while I was doing perl work. so to me pop'ing an array makes perfect sense. Sure, when there actually *is* an array to pop. In the following situation there is no array to actually pop (remove and return) the last element from, since you're using the return value of explode() while array_pop() expects a reference to a variable: $element = array_pop( explode( ',', $some_string ) ); No array to pop? .. explode returns an array. doesn't matter if its temporary or has a variable assigned to it. its still an array. -- Jasper Bryant-Greene Freelance web developer http://jasper.bryant-greene.name/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DOM XML compatible PHP4 & PHP5
On Monday 12 September 2005 02:08 pm, Florent Monnier wrote: > Hi, > > Is there a way to make dom xml applications compatible PHP4 and PHP5? > > Thanks You can use the PHP_VERSION predefined constant or the function_exists(string) http://us2.php.net/manual/en/function.function-exists.php What I did was created a Document Object. right now it only works with PHP5 I might add PHP4 support to it later tho when I have more time using this approach unless anyone can think of a better idea. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] php/mysql object id question..
On Wednesday 14 September 2005 03:42 pm, bruce wrote: > hi... > > i have the following psuedo code... > > i'm showing the pertinent parts, and eliminating the rest... > > -- > class sql > { > > function sql(...) > { > return false > > mysql_ > > mysql_ > } > > } > > $db = new sql(...) The new sql() is returning an object because that is what your asking for. now if you did a $db->sql() that'd return false. yes you did put a return false in the constructor but an object is what is being created and thus what is being returned. In my opinion a return anything within the constructor shouldn't be allowed. This might be the behavior in newer versions but I don't know. newer syntax is: class sql { function __construct (...) { ... } } truthfully when you do the $db = new sql(...); you are not running that function.. you are instantiating a new instance of sql which is invoking the object's constructor. > > echo "db" = .$db; > > > $db comes back as an object id.. even when i force a 'return false'. it > appears that no matter what i do, the class constructor returns an object > id!!! the weird thing is that it gets to the 'return false' and then still > seems to return the 'object id' i've also replaced 'false' with other > values to see if it made a diff.. it didn't which is good... i would have > really hit the roof then!! > > so.. why is this behavior occuring. > > any ideas as to why? > > or, am i just too tired right now! > > thanks > > bruce > > ps.. i could use the $db, object ID, and try to see if it actually access > the db, in order to determine if it actually exists. but i shouldn't have > to do that... the class should return false!!! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysql query
On Wednesday 14 September 2005 07:36 pm, Jesús Alain Rodríguez Santos wrote: > I have a table colum in mysql with two fields: day and month. I > would like to know if it's possible to make a query where I can > determine if exist days before to a selected day, for example: > if I have in my table: > day 19 - month 05, I wish to know if there are previous days > inserted at the 19, the days they are not inserted in the table, > they are inserted according your selection, what I want to get is > that every time that you insert a day, I want to check if there > are days previous to the one already inserted in the table in the > same month, in case that there are not them then they owe you > to insert together with the one selected, > I wait they understand me what I want: > I work php/mysql. create table tableA ( day int, month int ); select * from tableA where month=5 and day < 19; This will select everything from the 5th month and before the 19th day of the 5th month. Is that what you were going for? > > sorry for my english i'm cuban > Thank you and excuse the nuisances > > > > -- > Este mensaje ha sido analizado por MailScanner > en busca de virus y otros contenidos peligrosos, > y se considera que está limpio. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Quick Poll: PHP 4 / 5
On Tuesday 13 September 2005 05:52 pm, Ryan A wrote: > [x] I never work with PHP 4 anymore, all my work is with PHP 5 so far I've not found any hosts that do PHP5, however I do all my own hosting anyway. I've switched to use PHP5 because I was interested in doing XSL, and the concept of doing objects intrigues me. XSL support in 5 is far superior. It's a walk in the park now, where as before it was quite confusing. I'm currently doing a project where the client doesn't know what she wants... because of this I'm constantly having to redo sections to add what she wants. So taking this approach for this client has saved me from 10 times more work. I personally can't wait for PDO. I do lots of projects that all use SQL (SQLite, PostgreSQL and MySQL) Right now I have to recode everything to use the right DB. with my newest project I'm using SQLite with a custom Object to handle the DB Object. It's actually design with PDO in mind. After they get PDO in and working well It'll save me hours of work. From that Website about the 6 dumbest ideas. I guess you could say I'm an "early adopter" I like ideas that'll save me time in the long run, even if I'm the one that has to do tons of testing to make it usable. The long run is what matters to me. If I can spend time learning, testing.. and then later be able to do something in 5 mins that'd take 15 the old way.. I'm up for it. Has to be someone to do the testing to bring projects forward isn't there ? ;) From the opposite side of the spectrum I have had my share of upgrade issues. One was from 5.0.4 to 5.0.5 $this->urlArr[0] = array_pop($arr = explode("&",$this->urlArr[0])); I still have to scratch my head as to why I *need* that "$arr = " prior to 5.0.5 this was not needed. $this->urlArr[0] = array_pop(explode("&",$this->urlArr[0])); Perhaps someone here could tell me what was change to make this happen.. and how does that change make the engine better? It seemed to work perfectly fine before. I've also had to upgrade a few classes written for PHP4 specifically ones that like to use: var $variable; Overall, If you can upgrade to 5 .. do so. the advantages in my cases have been so nice. If you can't upgrade, Don't. Use what works. I personally would urge you to upgrade to 5 if you wanna get in deep with objects. I'm sure that 3 and 4 can do them just fine. but whats the use of learning how to do OOP in something that has been updated? Or worded differently, Why learn old ways when you can benefit from newer ideas/implementations ? It'd be like putting logs under a platform and repositioning the log that came out the back in the front again as a way to move something instead of wagon just because it's always worked before. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Quick Poll: PHP 4 / 5
Can't expect everything to be done right on the first try. But it sure was a big annoyance. Great to hear that work is being done to improve on this. I personally would rather it just be silently ignored as to me an error line at the top is the same as it not working at all. Would love to find a tool that could go over code and output errors like this tho. Provide a better solution or whatever along with all the dumb mistakes that PHP is ignoring for you. With my experiences I have never used pointers or references in PHP. I'm sure they are powerful and all. but I just don't want to mess with them or have worry about them. That's just 1 thing in programming I don't have much experience with. I give a function a variable and I think I'm passing the value. if the function takes the reference and modifies that.. oh well.. I got my result back that's all I care about :) as for the sort thought. If the programmer does that and can't figure out what's going on.. they obviously didn't read the manual or just don't know basic programming ;) bool sort ( array &array [, int sort_flags] ) Returns bool.. that's not an array ;) If it takes an array but doesn't return an array.. it must operate on the passed in array if it didn't what a useless function. Lets sort the array and say yah we sorted it but you can't have it :) So yes a bug. But for those that want to be able to grab only what we need. in my case array_pop's returned element. I don't wanna be hassled with the "are you sure you wanted to ignore part of what we did?" It's almost like every program asking "are you sure you wanted to close me?" everytime I get asked that I always think... "I did just click the X.. so Yah..." Just my 2 cents. I'm sure you guys will come up with something.. either way PHP is the only language I'll use for a website. Thank you very much for the detailed reason behind this. On Friday 16 September 2005 09:28 am, Rasmus Lerdorf wrote: > Stephen Leaf wrote: > > $this->urlArr[0] = array_pop($arr = explode("&",$this->urlArr[0])); > > > > I still have to scratch my head as to why I *need* that "$arr = " > > prior to 5.0.5 this was not needed. > > $this->urlArr[0] = array_pop(explode("&",$this->urlArr[0])); > > This is a much misunderstood issue. And we are still contemplating the > best way to handle this. Let's take a step back to a really simple > example: > > function foo() { > return 3; > } > function bar(&$arg) { > $arg = "banana"; > } > bar(foo()); > > What do we do with code like this? If you follow it through it is > essentially doing: > > 3 = "banana"; > > which makes very little sense and is probably something the developer > would want to know about. PHP 4.3.x happily let you do this, and in > some circumstances this could even corrupt memory. PHP 4.4 and higher > have fixed this memory corruption problem, and at the same time since we > are now able to detect this we can throw an error to let you know that > your code is probably not doing what you intended. > > Now, in your example you are doing: > > $a = array_pop(explode("&","a&b")); > > to get the last element from the explode. The issue with array_pop() > and other similar functions is that they do 2 things. They modify the > array (by removing the last element) and they return something (the > removed element in this case). When you pass in the result of explode() > you are passing in something that doesn't have any permanent storage > associated with it. Internally in PHP this is known as a temp var. You > can't make a reference to a temp var. In our simpler example it is like > trying to do &3 which doesn't make any sense. So in this case > array_pop() has no place to store the modification. Your code happens > to not care about that and only cares about the returned value. > > The real question here is whether we should silently ignore cases where > such an argument modification is thrown away. In the case of > array_pop() it may make sense. But how about this: > > sort(explode("&","a&b")); > > sort() has just one purpose. That is to sort the passed array in place. > The above line of code is a really slow line of code that does > absolutely nothing because we are passing in something that goes out of > scope as soon as the call is done. This line of code in a PHP program > is an obvious bug. Now, if we change this to: > > sort($a=explode("&","a&b")); > > then it suddenly makes se
Re: [PHP] Re: Using DOM object, how?
On Monday 19 September 2005 05:27 am, Jasper Bryant-Greene wrote: > Ken Tozier wrote: > > I don't see any obvious DOM method for including scripts or css links > > like "". Do you have > > to put them in some other type of node like a processing instruction or > > a comment? > > $dom = new DOMDocument('1.0', 'UTF-8'); > > $script = $dom->createElement('script'); > $script->setAttribute('type', 'text/javascript'); > $script->setAttribute('src', 'bobo.js'); > > $dom->appendChild($script); > ?> I would be extremely careful with this.. because sadly PHP's XML generator uses the short form whenever possible. will *NOT* work in most browsers such as FireFox.