[PHP] Re: PEAR installation error
Hi Alistair, There was a snafu in the PHP release process, PHP 5.2.0 shipped with an outdated go-pear.phar for some reason, you can fix this by downloading http://pear.php.net/go-pear.phar and saving it as PEAR/go-pear.phar in the unzipped windows distribution. Then, when you run go-pear.bat it will install properly. The [EMAIL PROTECTED] mailing list is a great resource for installation questions, and also general PEAR questions once you get it successfully installed. Good luck, Greg Alistair Tweed wrote: > Hi! > > I am keen to install PEAR and start using it, but encounter the same error > on two different XP machines and would be extremely grateful for any help > you can offer. > > Please see below for an account of the error. > > Best Regards and thanks in advance, > > Alistair > -- > > > Are you installing a system-wide PEAR or a local copy? > (system|local) [system] : local > Please confirm local copy by typing 'yes' : yes > > Below is a suggested file layout for your new PEAR installation. To > change individual locations, type the number in front of the > directory. Type 'all' to change all of them or simply press Enter to > accept these locations. > > 1. Installation base ($prefix) : C:\server\PHP > 2. Binaries directory: C:\server\PHP > 3. PHP code directory ($php_dir) : C:\server\PHP\pear > 4. Documentation directory : C:\server\PHP\pear\docs > 5. Data directory: C:\server\PHP\pear\data > 6. Tests directory : C:\server\PHP\pear\tests > 7. Name of configuration file: C:\server\PHP\pear.ini > 8. Path to CLI php.exe : C:\server\PHP\. > > 1-8, 'all' or Enter to continue: > Beginning install... > Configuration written to C:\server\PHP\pear.ini... > Initialized registry... > PHP Warning: Cannot use a scalar value as an array in > phar://go-pear.phar/PEAR > Command.php on line 268 > PHP Warning: Cannot use a scalar value as an array in phar://go-pear.phar > /PEAR > Command.php on line 268 > PHP Warning: Cannot use a scalar value as an array in > phar://go-pear.phar/PEAR > Command.php on line 268 > PHP Warning: Cannot use a scalar value as an array in phar://go-pear.phar > /PEAR > Command.php on line 268 > PHP Warning: Cannot use a scalar value as an array in > phar://go-pear.phar/PEAR > Command.php on line 268 > PHP Warning: Cannot use a scalar value as an array in phar://go-pear.phar > /PEAR > Command.php on line 268 > Preparing to install... > installing phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar- > 1.3.1.tar... > installing phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt- > 1.2.tar... > installing phar://go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.4.11.tar... > > PHP Warning: Cannot use a scalar value as an array in phar://go-pear.phar > /Arch > ve/Tar.php on line 2334 > PHP Warning: Cannot use a scalar value as an array in phar://go-pear.phar > /Arch > ve/Tar.php on line 2338 > Could not get contents of package "". Invalid tgz file. > Cannot initialize 'phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar- > 1.3.1. > ar', invalid or missing package file > PHP Warning: Cannot use a scalar value as an array in phar://go- pear.phar > /Arch > ve/Tar.php on line 2334 > PHP Warning: Cannot use a scalar value as an array in phar://go-pear.phar > /Arch > ve/Tar.php on line 2338 > Could not get contents of package "". Invalid tgz file. > Cannot initialize > 'phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt- > 1.2 > tar', invalid or missing package file > PHP Warning: Cannot use a scalar value as an array in phar://go-pear.phar > /Arch > ve/Tar.php on line 2334 > PHP Warning: Cannot use a scalar value as an array in phar://go-pear.phar > /Arch > ve/Tar.php on line 2338 > Could not get contents of package "". Invalid tgz file. > Cannot initialize 'phar://go-pear.phar /PEAR/go-pear-tarballs/PEAR- > 1.4.11.tar', > nvalid or missing package file > PHP Warning: Cannot use a scalar value as an array in phar://go-pear.phar > /PEAR > Command/Install.php on line 427 > PHP Warning: Cannot use a scalar value as an array in phar://go- pear.phar > /PEAR > Command/Install.php on line 427 > PHP Warning: Cannot use a scalar value as an array in phar://go-pear.phar > /PEAR > Command/Install.php on line 427 > PHP Warning: Cannot use a scalar value as an array in phar://go- pear.phar > /PEAR > Command/Install.php on line 429 > > install failed > Press any key to continue . . . > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] E_RECOVERABLE_ERROR - 5.1.6 to 5.2.0
Roman Neuhauser wrote: > # [EMAIL PROTECTED] / 2007-01-02 21:23:02 +0100: >> David CHANIAL wrote: >>> We are preparing the upgrade of PHP for our customers, but, after some >>> tests, >>> we have a migration "problem" caused by the news E_RECOVERABLE_ERROR. >>> >>> So, even if the upgrade guide (http://www.php.net/UPDATE_5_2.txt) talk >>> about >>> the method to handle this new errors (by using try/catch), they don't talk >> there is no mention of try/catch - it seems that the rather unfortunate word >> 'catchable' was used to describe the act of setting up a user defined error >> handler >> (see: http://php.net/manual/en/function.set-error-handler.php) to handle >> errors >> that are triggered by the php core. [errors != exceptions] > > Unfortunately. Consider this: > > function f($any) > { > printf("%s\n", $any); > } > > Innocent enough? It's an E_RECOVERABLE_ERROR if $any is an object > without __toString(). It's also an example of a former C coder's understanding of how to do things in PHP. Not only is this extremely inefficient (a function call is significant overhead in PHP) it is doubly inefficient through the unnecessary use of printf(). printf() is best used when you are modifying the display of the output, the %s modifier by itself is pointless in PHP. function f($any) { echo $any . "\n"; } This has no E_RECOVERABLE_ERROR possibility and is far more efficient. Better yet, replace f($blah) with echo $blah . "\n" This is a good example of how the flexibility of PHP can bite you, but is also a good example of how bad coding adds both complexity and inefficiency to the resulting software. If f() is called often, there might be a noticeable speedup if it were replaced. I once had a complex database ORM-HTML mapping app that was about 10% faster when I replaced all the "" strings with '' strings. This was on a slow machine with an early PHP, but little things like this can be very important. Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] E_RECOVERABLE_ERROR - 5.1.6 to 5.2.0
Robert Cummings wrote: > On Thu, 2007-01-04 at 10:54 +, Roman Neuhauser wrote: > >> echo $blah . "\n" is *not* equivalent to printf("%s\n", $blah) >> > > H, could you explain to me how it is different? I would always use > the former unless I specifically needed formatting provided by printf(), > and since there no formatting in the above printf() the echo to the best > of my knowledge is indeed equivalent. Hi, It is exactly the same (elegantly proving my point, btw) Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: most powerful php editor
Vinicius C Silva wrote: > hi everyone! > > i'd like to ask something maybe commonly asked here. what is the most > powerful php editor? I am Yours, Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: using return in include files
Aaron Axelsen wrote: > I'm trying to figure out what the desired behavior is of using the > return function to bail out of an include page. > > I did some testing, and this is what I concluded. > > First, I created the following file: > > if (defined('TEST_LOADED')) { > return; > } > define('TEST_LOADED',true); > echo "blah blah blah blah"; > ?> > > I then called it as follows: > include('test.php'); > include('test.php'); > include('test.php'); > > The output is: > blah blah blah blah > > Second, I changed the test.php file to be the following: > > if (defined('TEST_LOADED')) { > return; > } > define('TEST_LOADED',true); > echo "blah blah blah blah"; > > function myFunc($test) { > > } > ?> > > When I load the page now, it throws the following error: PHP Fatal > error: Cannot redeclare myfunc() > > It appears that if there are functions in the include page that you > can't use return to bail out. What is the desired functionality in this > case? Is this a bug in how php handles it? or was return never designed > to be used this way? > > Any thoughts are appreciated. Hi Aaron, Unfortunately, the only way you can prevent the parse error is to use a conditional function, return won't cut is, as the file is re-parsed every time you include it, and all classes/functions are re-parsed before the run-time if() is processed. This will work, but does slow down opcode caches and introduce potential instability with them, as the added complexity is very unfriendly to optimization. Of course, you are much better off taking advantage of the include_once[1] language construct, or separating your need-to-be-included-many-times file from any function or class definitions. Greg http://www.php.net/include_once -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Package php code
Peter Lauri wrote: > Hi, > > > > Is there any similar way to package PHP software as Java with a jar file or > similar? I have never seen it, because then would probably Smarty for > example be packaged already :-) This question came out of the blue when I > was thinking about how to deliver some plugins to a customer. The only live example of a php jar (phar) is bundled with PHP newer than PHP 5.1.0, and you can see it at http://pear.php.net/go-pear.phar or http://pear.php.net/install-pear-nozlib.phar. These packages were created using the PHP_Archive package at http://pear.php.net/PHP_Archive. There is also an unrelated project that calls itself PHK that claims to have more features, but I have not tried it. Although PHP_Archive-based phars work, I've been working with Marcus Boerger on the native PHP extension Phar (http://pecl.php.net/phar) which will allow far more flexibility and power as well as performance. However, any software that relies upon include_path needs to be modified to work with phar, which can be a royal pain, depending on how it was designed initially. The best example of the packaging script that might be necessary is at http://cvs.php.net/viewvc.cgi/pear-core/make-gopear-phar.php Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: What search algorithm does in_array() use?
Ken Dozier wrote: > Does in_array() use a search algorithm (i.e., binary search), or does it > check sequentially each element in the array? > > I am using in_array() within a while{} loop to check query results against > an access-list array to produce a third array containing items that > successfully passed the comparison test. Because the two starting arrays in > the worst-case scenario can have 8,000 items each, the loop is timing out. > Advice or alternative methods are appreciated. > > Code Sample: > function check_results($results, $access_list) > { # Check for $results in array $access_list and > # add matches to array $match. > > $result = false; > $match = array(); > > while ($r = mysql_fetch_row($results)) > { if ( in_array($r[0], $access_list) ) > { $match[] = $r; } > } > > if ( count($match) > 0 ) { $result = $match; } > > return $result; > } > ?> Hi Ken, Since arrays are hash tables in PHP, it would be far faster to use an associative array. How? $access_list = array_flip($access_list); then if (isset($access_list[$r[0]])) However, this sounds more like a design issue with the SQL that creates $results. You can do the in_array natively in SQL with "WHERE otherthing IN ("thing1", "thing2",...)" which would automatically filter out the non-matches in a far more efficient manner, perhaps increasing requests per second by an exponential factor. Of course, if $access_list is from external input (user input), you will need to escape the output, make sure you have the proper encoding, etc. so you can avoid SQL injection attacks and other nastiness, but that is another topic. If you are getting $access_list from another query, you could also try using a sub-query as in "WHERE otherthing IN (SELECT ...)" but this of course assumes you are are using MySQL >= version 4.1. In any case, you are definitely going to want to revisit the design of your queries before even starting with reworking your PHP. Good luck, Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: __construct __destruct in PHP 4
Peter Lauri wrote: > Hi, > > > > I have been trying going thru the PHP manual to find if there are any > equivalent to the __contruct and __destruct in PHP 4, but I cannot find any > solution for this part. I know it was introduced in PHP 5, but as __sleep > and __wakeup exist in PHP 4 already I was hoping there is something like > __init and __die in PHP 4 :-) Hi Peter, As you probably already know, PHP 4 constructors are functions named after the class Although destructor emulation is implemented in the PEAR class (destructor would be function _Foo), I don't recommend using a destructor in PHP 4. Instead, manually destruct your objects. PEAR does it with a shutdown function, so if performance is not a question, by all means, use PEAR's implementation. It has been battle-tested for years and years. However, I wouldn't bother with writing new code in PHP 4. It will be cheaper for you to switch hosting providers to one that allows you to use PHP 5. Why? You will waste tons of time working around reference issues that are non-existent in PHP 5 due to object handles. Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: REST, SOAP or XML-RPC?
Paul Scott wrote: > I am developing a webservice like module for our framework that will > enable downloads of module code into the framework modules from a remote > server. > > Basically what this should do is: > > 1. User requests a list of available stable modules from server > 2. User clicks on install from the returned list > 3. Client code will download a tgz/zip module and plonk it in the users > modules directory (taken care of) > 4. Framework then unzips/untars it and installs (taken care of) > > My question here is... > > For the server/client code, I am thinking around REST (much the same way > as the PEAR channel server works). Is this the wisest choice? Should I > rather go with FTP or a mail request or something? If I go for FTP, that > will require the PHP FTP extension, how common is that in shared hosting > environments? > > The file size of a typical module is around 100k, and we must take into > account that this is in/for bandwidth starved Africa. Is REST/SOAP > robust enough to do that? > > Any help would be greatly appreciated! Hi Paul, Why not use PEAR itself? The last chapter of my book (http://www.packtpub.com/book/PEAR-installer) is a step-by-step tutorial on designing just such a module that would allow downloads of module code from a remote server. It also includes all the code, which is publicly and freely available from the pear.chiaraquartet.net channel (package MyBlog). The code is a useful example of embedding the PEAR installer and of designing customized REST, but it might be tricky to understand the design methodology without the prose of the book. The question of how to do what you describe is something I have thought about a LOT because of the requirements of the PEAR Installer. One of the specific design choices in PEAR 1.4.0 and newer was to make it easy to embed PEAR to act as a plugin module. The chapter in question also examines other successful attempts to design remote plugin repositories including Serendipity's Spartacus and Seagull's use of the PEAR Installer to show other ways of implementing a plugin manager. One thing I found very interesting was that even though Spartacus is extremely lightweight, it was easy to design a much more sophisticated plugin manager using PEAR with the same number of lines of code. You need not use PEAR's actual installation process unless you find it convenient (I do - file transactions are a must-have if you want to be able to recover from botched downloads and so on). In any case, do check out the solution in the book, I'm sure it will solve the problem you describe quite elegantly. Good luck, Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: How to parse PHP tags in a string?
Zak Mc Kracken wrote: > Hi all, > > Is there a PHP function that parses a string as it was the content of a > PHP file? > > I have a CMS application and editors write the news items text into a > text area. Since they have some knowledge of PHP, I'd like to allow them > to insert or and have the content blocks parsed and > executed. OK, this could be easily done parsing the string and passing > the block contents to eval(). However I wonder wether there is some > function already doing that (maybe in a more efficient way). > > Thanks a lot in advance. Hi, This is a very dangerous thing to do, as it will allow execution of arbitrary PHP code. I highly recommend that you not allow this. Instead, some kind of plugin system could be allowed where editors can specify a plugin (something like [plugin name="blah" param1="blah" param2="halb"]) and they upload the PHP code to a file on the server, register that file as the plugin "blah" and go from there. Anything else is begging to get the site hacked and cause yet another vulnerability in a php app. Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Find midpoint between two points
M5 wrote: > I found a nice javascript function that takes two points of latitude and > longitude and returns a midpoint. I'm now trying to rewrite in PHP, but > having some problems. Here's the original javascript function, taken > from http://www.movable-type.co.uk/scripts/LatLong.html : > > LatLong.midPoint = function(p1, p2) { > var dLon = p2.lon - p1.lon; > > var Bx = Math.cos(p2.lat) * Math.cos(dLon); > var By = Math.cos(p2.lat) * Math.sin(dLon); > > lat3 = Math.atan2(Math.sin(p1.lat)+Math.sin(p2.lat), > > Math.sqrt((Math.cos(p1.lat)+Bx)*(Math.cos(p1.lat)+Bx) + By*By ) ); > lon3 = p1.lon + Math.atan2(By, Math.cos(p1.lat) + Bx); > > if (isNaN(lat3) || isNaN(lon3)) return null; > return new LatLong(lat3*180/Math.PI, lon3*180/Math.PI); > } > > > And here's my PHP variant, which isn't working: > > function midpoint ($lat1, $lng1, $lat2, $lng2) { > $dlng = $lng2 - $lng1; > $Bx = cos($lat2) * cos($dlng); > $By = cos($lat2) * sin($dlng); > $lat3 = atan2(sin($lat1)+sin($lat2), > sqrt((cos($lat1)+$Bx)*(cos($lat1)+$Bx) + $By*$By )); > $lng3 = $lng1 + atan2($By, (cos($lat1) + $Bx)); > $pi = pi(); > return ($lat3*180)/$pi .' '. ($lng3*180)/$pi; > } > > Any ideas why it's returning wrong values? Are you converting from degrees to radians? With identical input, the javascript function is identical to the PHP function (I tested to verify) I got this by reading at the bottom of the page: "* Notes: trig functions take arguments in radians, so latitude, longitude, and bearings in degrees (either decimal or degrees/minutes/seconds) need to be converted to radians, rad = π.deg/180. When converting radians back to degrees (deg = 180.rad/π), West is negative if using signed decimal degrees. For bearings, values in the range -π to +π (-180° to +180°) need to be converted to 0 to +2π (0°–360°); this can be done by (brng+2.π)%2.π where % is the modulo operator. View page source to see JavaScript functions to handle these conversions. * The atan2() function widely used here takes two arguments, atan2(y, x), and computes the arc tangent of the ratio y/x. It is more flexible than atan(y/x), since it handles x=0, and it also returns values in all 4 quadrants -π to +π (the atan function returns values in the range -π/2 to +π/2). * If you implement any formula involving atan2 in Microsoft Excel, you will need to reverse the arguments, as Excel has them the opposite way around from JavaScript – conventional order is atan2(y, x), but Excel uses atan2(x, y) * For miles, divide km by 1.609344 * For nautical miles, divide km by 1.852 * Thanks to Ed Williams’ Aviation Formulary for many of the formulae " Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: PHP/PEAR
Malcolm Pickering wrote: > Hello there, > > As a new user of PHP I am finding it extremely useful, very fast, and > rewarding. I was also delighted to find the already proven and maintained > extensions in PEAR. > > I have recently downloaded one of these extensions (HTML_Table) which is > proving to be a great time saver, but can you tell me, please, why every time > I access one of the associated pages or scripts my computer tries to dial > out. Yes, I am still on Dial-Up. Is this some vital function that is required > by your extension, or is there some information you need which has not > already been given? If it is neither of these, how do I stop it because I > find it infuriating. > > Hoping you can help me, Hi Malcolm, Sorry to hear about your trouble with HTML_Table. As you use PEAR packages, you should also know about the [EMAIL PROTECTED] support list, PEAR users and developers regularly answer queries on package usage and help with troubles like yours with possibly more detail than you will find on php-general. In this case, I have to agree, this sounds more like a browser issue. HTML_Table does not use any remote access functionality, the suggestion that it would try to do so is not very accurate or helpful, as the only PEAR libraries that access the internet say so explicitly in their package description and/or documentation. The manual for PEAR is at http://pear.php.net/manual/en (english). Good luck, Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: LOL, preg_match still not working.
Beauford wrote: > Hi, > > I previously had some issues with preg_match and many of you tried to help, > but the same problem still exists. Here it is again, if anyone can explain > to me how to get this to work it would be great - otherwise I'll just remove > it as I just spent way to much time on this. > > Thanks > > Here's the code. > > if(empty($comment)) { $formerror['comment'] = nocomments; > } > elseif(!preg_match('|[EMAIL PROTECTED]&*();:_. /\t-]+$|', > $comment)) { > $formerror['comment'] = invalidchars; > } > > This produces an error, which I believe it should not. > > Testing 12345. This is a test of the emergency broadcast system. > > WAKE UP!! Hi, Your sample text contains newlines. If you wish to allow newlines, instead of " \t" you should use the whitespace selector "\s" Try that code sample, and you'll see that it says "ok" What exactly are you trying to accomplish with this preg_match()? What exactly are you trying to filter out? I understand you want to eliminate "invalid characters" but why are they invalid? I ask because there may be a simpler way to solve the problem, if you can explain what the problem is. Thanks, Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: FW: [PHP] Re: LOL, preg_match still not working.
Beauford wrote: > I pasted this right from my PHP file, so it is correct. Just to elaborate. I > have tested this until my eyes are bleeding. > > Sometimes this works sometimes it doesn't. > > One minute !!!##$$ This is a test &&%% will work the way it is supposed to, > the next minute it does not. > > It seems that the first time through it is fine, but on the second time and > on it is not. > So if I keep hitting submit on my form with the above string, it will be ok > on the first submit, but on subsequent submits it says there are invalid > characters. > > Suffice it to say, it is wonky. It seems like it works when it wants to. The problem is in the rest your code, not the regex, otherwise it would fail every time. Please post the code after removing sensitive passwords and other information, but leave as unaltered as possible. Only then can anyone help debug this problem. Thanks, Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: working with class inheritance
Jeff Taylor wrote: > Hey all, got a slight problem, where for some reasons my variables dont seem > to be getting stored in the child class: > > e.g > > class Parent > { > $private type; > > public function __construct() > { > } > >public function GetType() >{ > return $this->type; > } > } > > class Child implements Parent > { > $public function __construct() > > > $this->type= 'Child'; > } > } > > $Child= new Child(); > echo $Child->getType; > > Can u see any reason why the type would return null? Hi Jeff, Aside from your obvious parse errors, the main problem is that you are incorrectly using "private." Since you wish to access $type from the child class, you must use "protected" or declare a setter function as Roman suggested. However, setter functions are far less efficient than simply using protected: type='Child';} } ?> It should be noted that if you simply want to store the class name, a better approach is to use get_class() Of course, you may want to remove a prefix from the classname, in which case you could also use a simple __get()/__set() declaration that prevents accidental modification of object type: type , ' ' , $b->type; $a->type = 5; echo $a->type , ' ' , $b->type; ?> Regards, Greg -- Experience the revolution, buy the PEAR Installer Manifesto http://www.packtpub.com/book/PEAR-installer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: _Construct question
John Comerford wrote: > Hi Folks, > > I am still pretty new to PHP and I have a question regarding classes and > using _construct. Up until now I have been creating my classes as follows: > > class test1 { > var $name; > function test1($pName) { > $this->name = $pName; > } > } > > So I when I create a new class I can assign 'name' by doing '$t1 = new > test1("test1");' > > As part of another thread I noticed the _construct function which (if I > am correct) does more or less the same thing: > > class test2 { > var $name; > function _construct($pName) { > $this->name = $pName; > } > } > > I have fished around a bit and cannot find why one might be better than > the other. The only thing I can think is that maybe you need to use > _construct to be able to use "extends" ? > > Is this the case ? What is the advantage/disadvantage of using > _construct as opposed to using a function with the classname ? Hi John, The main advantage comes when you are extending a class. PHP 4: PHP 5: Aside from the benefit of not needing to remember the parent class name or type it in just to call the parent class constructor, another benefit is that a quick scan of the source code will allow you to find the constructor much more readily. You don't even need to know the classname. There are lots and lots of changes to the object model in PHP 5, see: http://www.php.net/manual/en/language.oop.php http://www.php.net/manual/en/language.oop5.php Greg -- Experience the revolution, buy the PEAR Installer Manifesto http://www.packtpub.com/book/PEAR-installer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: is pecl.php.net down?
martin wrote: > Since about 7 hours now i can't get on the pecl.php.net pages. The site > doesn't seem to be available. > > Does somebody know why? Hi Martin, The entire machine that runs pear.php.net and pecl.php.net was down for a very long time. It has recently come back up online, you should be able to use the website fully now. Thanks, Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve POST body?
Justin Frim wrote: > Sorry burst your bubble, but your solution isn't a viable one in my case. > php://input only works if the form is submitted using > application/x-www-form-urlencoded. > > Take your sample HTML code there and add enctype="multipart/form-data" > to the tag, and I'm pretty sure you'll find that php://input > contains no data. (Both PHP 5.2.1 running as a CGI on Windows and PHP > 5.2.0 running as an Apache module on FreeBSD exhibit this behaviour.) > > And before anyone asks, it *is* a requirement to accept > multipart/form-data submissions because that's the only way you can > properly implement a file upload on a web form. Good news and bad news. Rasmus reports on IRC: [21:57] We never buffer the data in file upload mode [21:57] it is streamed to disk, so no, you can't get it all in a variable like that [21:57] set a different content-type if you want to do that [21:57] assuming you have control over the client [21:58] can you do a file upload without multipart? [21:59] Well, if you want to pick a POST apart yourself, sure [21:59] set a mime type PHP doesn't understand and it will be in http_raw_post_data and then you can do whatever you want with it So the answer is "sort of." You would have to parse the POST data yourself, but it is technically a possibility. Regards, Greg -- Experience the revolution, buy the PEAR Installer Manifesto http://www.packtpub.com/book/PEAR-installer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] retrieve POST body?
Myron Turner wrote: > That's not been my experience. I've tested it with > enctype="multipart/form-data", since that's what you asked for, though > the enctype wasn't included in my sample code. I've run it on PHP > Version => 5.1.6 (Fedora core 4) and PHP 4.3.11 Fedora core 2. > Here it is on Fedora 2: >http://www.mturner.org/temp/post_data.php > The code is >http://www.mturner.org/temp/post_data.phps the enctype attribute should be in the tag, not the submit . Put it in and your php://input will disappear Greg -- Experience the revolution, buy the PEAR Installer Manifesto http://www.packtpub.com/book/PEAR-installer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: pecl in php5?
Per Jessen wrote: > I'm trying to install the pecl mailparse extension, but I'm not getting > very far: > > pecl install mailparse > pecl/mailparse requires PHP extension "mbstring" > No valid packages found > install failed > > "mbstring" does not seem to be a php extension, and in any case I built > php with "--enable-mbstring". > Can anyone help me get mailparse installed or at least figure out what's > going on? I'm using php-5.2.3. Hi Per, use pear install pecl/mailparse The difference between the "pear" and "pecl" commands is that "pecl" disables php.ini so that you can overwrite extension .so or .dll files that would otherwise be in use and locked for write. So, unless mbstring is built into PHP (not a loaded module in php.ini), you won't be able to install mailparse. Sorry for the inconvenience, this is the only extension in the lot that I've heard of with a dependency on a non-built-in extension. I would prod the mailparse maintainers to add a note to the package page or to the docs. Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Database includes
Bruce Cowin wrote: > I'm curious as to how everyone organises and includes their classes in > PHP5. Let's take a simple example that has 3 classes: customer, order, > and database. The database class has a base sql db class (I know there > is PDO and other things but this class is already written and working) > and classes that inherit from the base class for dev, test, and prod, > passing the associated logins. The customer and order will both use the > appropriate database class depending on which environment its in (e.g., > SalesDevDB, SalesTestDB, SalesProdDB). > > I don't want to have to go into the customer and order class code and > change which db class it uses when I move it from dev to test and from > test to prod. What's the proper way to handle this? Or am I way off > base? Hi Bruce, Use a factory or singleton pattern to instantiate your database objects, and you can centralize the choice. public $production = 'Dev'; // or 'Test' or 'Prod' static function factory($dbname, $args) { if (!class_exists($dname . self::$production . 'DB')) { require 'However/You/Find/It.php'; } $db = $dname . self::$production . 'DB'; return new $db($args); } Singleton would simply return a pre-instantiated object if it exists for that class type but is otherwise the same. Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] zlib.inflate vs. gzopen/fread
Hi all, I've run into a peculiar situation where the inflate implementation in the zlib.inflate filter fails to successfully inflate a gzipped file created using gzopen/gzwrite. The file is really quite simple. To replicate, download http://pear.php.net/get/PEAR-1.6.1.tgz and run this script: output is: string(0) "" bool(false) The results are the same when using file_get_contents(), readfile(), and also with the zlib.inflate example in the PHP manual. This is on a 64-bit system with PHP 5.2.4 CVS HEAD, although the zlib.inflate implementation hasn't changed substantially since 2005 (and yes, I also tested it without the 3-line patch introduced in PHP 5.2.1 to see if it was the cause). Can anyone else confirm the above behavior? Thanks, Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Questions about overloading and visibility in PHP5
Steve Brown wrote: > I've been doing a bunch of reading about objects and overloading in > PHP5, but I've got a couple of questions that I can't seem to find the > answer to online. Suppose the following code in PHP5.2.4: > > class foo { > public $x; > private $z = 'z'; > > public function __set ($name, $val) { > echo "Setting \$this->$name to $val...\n"; > $this->{$name} = $val; > } > > public function __get ($name) { > return "The value of $name is {$this->{$name}}.\n"; > } > } > ?> > > My questions are as follows: > > 1) It seems that the getter and setter are not called on every single > call. For example, if I do the following: > > $bar = new foo; > $bar->x = 'x'; > > There is no output. I would expect to see "Setting $this->x to x." remove "public $x" and it works. __set() is only called for non-existent variables. > Another example: > > $bar = new foo; > $bar->y = 'y'; > echo $bar->y; > > I would expect this to see "The value of y is y." but instead I just > get 'y' as output. So when do the various setters/getters get used? again, because your code sets $y with $this->{$name} = $value, the variable $y now exists, and so __get() is not called. If you're using normal variables, then you don't need setters/getters. Instead, if you store the values inside an internal array (for instance), then a setter/getter can help to abstract the array contents. For instance, this class: http://svn.pear.php.net/wsvn/PEARSVN/Pyrus/trunk/src/PackageFile/v2/Developer.php?op=file&rev=0&sc=0 (which is under development currently for the next incarnation of the PEAR installer) allows logical manipulation of maintainers of a package within package.xml. Instead of either direct array manipulation or the old way, which was a complex method call that is easy to mis-order: $pf->addMaintainer('cellog', 'Greg Beaver', '[EMAIL PROTECTED]', 'yes'); One can do: $pf->maintainer['cellog'] ->name('Greg Beaver') ->email('[EMAIL PROTECTED]') ->active('yes'); and then values can be retrieved using normal stuff like: echo $pf->maintainer['cellog']->email; The entire time, the class is abstracting stuff that would be really complex as it is actually accessing the underlying XML of the package.xml directly when making the modifications. The examples you give don't need this kind of complexity. > 2) It seems that getters ignore the visibility of properties. Why is > this? For example: > > $bar = new foo; > echo $bar->z; > > I would expect this to throw an error about accessing a private > member, but it outputs "The value of z is z." just fine. If I remove > the __get() overloader, an error is thrown. private properties simply don't exist outside the class, so you can create public properties on external access with impunity. You should open a documentation bug for this at bugs.php.net Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: http://go-pear.org?
Steve Brown wrote: > I'm trying to install Pear on OSX, but http://go-pear.org/ doesn't > seem to be resolving. Pear manual states I should: > > curl http://go-pear.org/ | php > > but this fails and > > dig go-pear.org > > reveals that the name does not resolve. Is there a package somewehre > I can download and install? If you're using PHP 5.1.0 or newer, grab http://pear.php.net/go-pear.phar Otherwise use http://peear.php.net/go-pear The best list for general PEAR questions is [EMAIL PROTECTED] Thanks, Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [ANNOUNCE] TODO parser
Edward Vermillion wrote: > > On Apr 27, 2007, at 8:24 PM, Daevid Vincent wrote: > >> For a long time I've wanted a tool that would traverse my source code to >> find all those little forgotten "TODO" entries. >> > > [snip] > > Doesn't phpDocumentor (http://phpdocu.sourceforge.net/) do that already? Hi, phpDocumentor processes @todo tags in a docblock, but not //TODO or other similar things. Greg -- Experience the revolution, buy the PEAR Installer Manifesto http://www.packtpub.com/book/PEAR-installer -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: possible to "move_uploaded_file" to a variable instead a file?
Mark wrote: > hey, > > i`m wondering if it`s possible to move a uploaded file inside a variable. > i would like to know this because i`m currently writing a database backup > script and in there the user uploads a sql file that gets executed. now i > _don`t_ want the file to be stored on the server!! simply because that`s > not > safe. however i do want to store it inside a variable and than run the > database query. > > any idea`s on this? Hi Mark, Instead of move_uploaded_file($uploaded, $newlocation), use: HOWEVER, what you are doing is a *really* bad idea regardless of where you save the uploaded file. No matter how much you trust your end users, running SQL uploaded directly on the database is extremely dangerous. Instead, you should define a simple set of questions based on the user and the databases they have access to, i.e. a multi-select box that allows the user to select which databases to backup, and possibly allow an .ini file to be uploaded defining which tables in databases to back up, and then from the .ini file construct the actual SQL that will be run. Your ini-to-sql script should also contain verification to ensure that, for instance, the user is not requesting to "back up" the mysql table and acquire all the people's accounts/passwords. If the user wishes to back up the user_blah database, tables foo and bar, your ini could be: [user_blah] tables = foo,bar Or, for all: [user_blah] tables = * Otherwise, you're just asking to get shot in the digital foot. Good luck, Greg -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Installing PEAR on machines without internet access.
Lester Caine wrote: > I've been going through the hoops documenting installation and recovery > notes for my customer sites. The majority of these run local web > services with no internet access from the servers, so with the > increasing reliance on PEAR extensions, I'm looking to the correct way > to 'install' PEAR packages. > > Currently I just clone the PEAR directory from another machine. Is this > the only way ? This will work if and *only* if the paths are the same on the destination machine. If so, this works fine. Otherwise, you can install PEAR directly just as PHP does, using install-pear-nozlib.phar, check out the pear/ directory in your unix-based PHP distribution for the Makefile.frag that shows usage. After PEAR is installed, you can install packages directly from tarball via the command-line. pear install Package-1.2.3.tgz Greg P.S. PEAR questions are best asked on [EMAIL PROTECTED], the best support for PEAR is on that list. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php