Comments for "PHP_Compat"

» Submit Your Comment
Comments are only accepted during the "Proposal" phase. This proposal is currently in the "Finished" phase.
» Comments
  • Alan Knowles  [2004-04-27 09:23 UTC]

    you can add (there's an example on the page)

    having chatted on IRC, it may just be easier not to have any 'loader', just say the usage is:
    if (!function_exists('file_get_contents')) {
    require_once 'PHP/Compact/Funct/file_get_contents.php';

    Although not in the true spirit of PEAR (eg. package of classes) - I think it's a good idea..
  • Davey Shafik  [2004-04-27 09:42 UTC]

    This should be called PHP_Compat, because it is possible that we may implement some classes and constants and such too....

    I think this is a good idea, I did once propose a package called BackPort which you may want to take a look at... its overkill for this, I would imagine
    - Davey
  • Ian Eure  [2004-04-27 12:27 UTC]

    I like this idea a lot, though I agree with Davey's points.

    It would be nice to see some sort of additional layer built on top of this with function profiles of different PHP versions - so you could e.g. PHP_Compat_Func::requirePhpVersion(4.2.3); and have it bump you up to a 4.2.3 compatibility level. Consider this a wishlist item, I'd be quite happy just to see a central place for compatibility hacks.

    I have cleaned up pg_(un)escape_bytea() functions (originally from a contributor to the PHP manual) which could be added.
  • Aidan Lister  [2004-04-27 13:52 UTC]

    Ian, surely this would result in loading a heap of un-needed functions. (Although I do love the idea).

    Perhaps we should make a sub section for Compatability, we have PHP_CompatInfo - perhaps this should be PHP_Compat_Info, in line with PHP_Compat_Func

    I'm just throwing ideas around, feel free to shut them down!
  • Stig Bakken  [2004-04-27 19:27 UTC]

    Just make sure you wrap the function definitions in "if (!function_exists...)", because some packages already provide file_get_contents() etc.

    IMHO, compatibility functions should be one-function-per-file and installed in $PHP_DIR/_compat/function/function_name.php. Usage would be:

    require_once "_compat/function/file_get_contents.php";


    if (!function_exists("file_get_contents")) {
    include_once "_compat/function/file_get_contents.php";
  • Davey Shafik  [2004-04-29 15:22 UTC]

    I just had a thought,

    If we do something like:

    class PHP_Compatibility {
    function require($function,$type = 'function') {
    if ($type == 'function') {
    // this allows us to provide compatibility classed too
    if (!function_exists($function)) {
    require_once 'PHP/Compatiblity/functions/' .$function. '.php';

    And the user just does:

    PHP_Compatiblity::require('glob'); for example
    its *much* better than them having to do the function_exists tests and such themselves over and over....

    - Davey
  • Aidan Lister  [2004-04-30 00:03 UTC]

    I'm not sure I agree Davey,

    If I was using one of the functions in my package, I'd find it easier to just include the file.

    However, your method is a lot more extensible, and keeps PEAR a class library.
  • Aidan Lister  [2004-05-02 06:03 UTC]

    I've done a rough version of the class (see links), any comments before I call-for-votes?
  • Aidan Lister  [2004-05-08 06:54 UTC]

    Any more comments before I call for votes?

    If the name is fine, I'll commit to CVS