pear:faq

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
pear:faq [2010/08/17 00:52] – created clockwerxpear:faq [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== FAQ ====== ====== FAQ ======
 .. and other mailing list answers. .. and other mailing list answers.
 +
 +This page is meant to be a quick and easy scratchpad of good answers and ideas - candidates to be polished and migrated into the proper FAQs.
 +
 +===== Where's the proper FAQs? ======
 +  * [[http://pear.php.net/manual/en/faq.users.php|Users]]
 +  * [[http://pear.php.net/manual/en/faq.devs.php|Developers]]
 +
 +===== How do I become a PEAR developer? =====
 +http://pear.php.net/manual/en/developers-newmaint.php
  
 =====  Non-PEAR, PHP package deployment through official PEAR channel? ===== =====  Non-PEAR, PHP package deployment through official PEAR channel? =====
Line 21: Line 30:
  
 http://saltybeagle.com/2008/12/using-simplechannelserver-to-manage-a-pear-channel-on-google-code/ = pretty easy to do and ends up letting you host on google code http://saltybeagle.com/2008/12/using-simplechannelserver-to-manage-a-pear-channel-on-google-code/ = pretty easy to do and ends up letting you host on google code
 +
 +===== Fixing code =====
 +Fixing a unit test / E_DEPRECATED problem: Let's take for example, [[pear:package:Net_DNS]] - http://pear.php.net/package/Net_DNS/
 +
 +<code bash>
 +# Check the open bugs to see if there is one already
 +# http://pear.php.net/package/Net_DNS/
 +
 +# Grab the code from svn:
 +$ svn co http://svn.php.net/pear/repository/packages/Net_DNS/trunk Net_DNS
 +
 +# Next, run the unit tests to make sure it all works on your environment:
 +$ cd Net_DNS
 +$ php tests/AllTests.php
 +
 +# If the tests don't run, you may need to install phpunit or other dependencies
 +$ pear channel-discover pear.phpunit.de
 +$ pear install phpunit/phpunit
 +$ php tests/AllTests.php
 +
 +</code>
 +
 +Hopefully, they all pass!
 +
 +So, there are things to fix with ereg.
 +<code>
 +WARNING: Function 'ereg' is deprecated, please use 'preg_match' instead in file ./Net_DNS/Net/DNS/RR/TXT.php line 62
 +
 +WARNING: Function 'ereg' is deprecated, please use 'preg_match' instead in file ./Net_DNS/Net/DNS/RR/SRV.php line 67
 +WARNING: Function 'ereg' is deprecated, please use 'preg_match' instead in file ./Net_DNS/Net/DNS/RR/MX.php line 61
 +
 +WARNING: Function 'ereg' is deprecated, please use 'preg_match' instead in file ./Net_DNS/Net/DNS/RR/NAPTR.php line 79
 +WARNING: Function 'ereg' is deprecated, please use 'preg_match' instead in file ./Net_DNS/Net/DNS/RR/SOA.php line 77
 +</code>
 +
 +The first - the constructor of Net_DNS_RR_TXT has:
 +<code php>
 +            ereg('("[^"]*"|[^ \t]*)[ \t]*$', $data, $regs);
 +</code>
 +
 +It's probably best to start with a unit test that shows the error up:
 +<code php>
 +    function Net_DNS_RR_TXT(&$rro, $data, $offset = '') {
 +       ... snip ...
 +       if ($offset) {
 +           .... snip ...
 +       } elseif (is_array($data)) {
 +           .... snip ...
 +       } else {
 +            $data = str_replace('\\\\', chr(1) . chr(1), $data); /* disguise escaped backslash */
 +            $data = str_replace('\\"', chr(2) . chr(2), $data); /* disguise \" */
 +
 +            ereg('("[^"]*"|[^ \t]*)[ \t]*$', $data, $regs);
 +            $regs[1] = str_replace(chr(2) . chr(2), '\\"', $regs[1]);
 +            $regs[1] = str_replace(chr(1) . chr(1), '\\\\', $regs[1]);
 +            $regs[1] = stripslashes($regs[1]);
 +
 +            $this->text = $regs[1];
 +    }
 +</code>
 +
 +Would be something like:
 +<code php>
 +class Net_DNS_RR_TXTTest extends PHPUnit_Framework_TestCase {
 +
 +    public function testShouldConstruct() {
 +       $foo = new Net_DNS_RR_TXT(null, "fakedatainhere");
 +       $this->assertSame("something", $foo->text);
 +    }
 +
 +}
 +</code>
 +Run it to check it fails:
 +<code bash>
 +$ php tests/AllTests.php
 +</code>
 +So; to make the actual change:
 +http://au.php.net/ereg is probably best replaced with preg_match() - however, you might need to convert the regex too.
 +
 +Make the change, run the tests, and hey presto everything should pass.
 +
 +Make yourself a universal diff:
 +<code bash>$ svn diff > myPatch.txt</code>
 +
 +... and upload it to a bug report / pastebin.
 +
 +===== How do I edit this freakin' wiki? =====
 +Login with your SVN credentials.
 +
 +
pear/faq.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1