0

How can I make the deprecated functions to work in PHP's latest version? I don't want to change the alternate function of it in each and every page, it's highly impossible in the maintenance project which I have. So please let me know if there is a way to make the deprecated functions to work.

gopivignesh.m
  • 1,103
  • 2
  • 11
  • 19
  • 1
    which specific deprecated function you need does NOT work in the latest PHP version? – Walter Tross Jun 29 '12 at 12:11
  • 1
    `split()` is deprecated but not outphased. I think you can very gradually move from `split()` to `explode()` and `preg_split()`. No hurry! – Walter Tross Jun 29 '12 at 12:17
  • nop, `split()` isn't working on PHP 5.3.8 – Adi Jun 29 '12 at 12:17
  • @Adnan Shammout: OK, maybe I'm not up-to-date: in what way does `split()` not work on PHP 5.3.8? – Walter Tross Jun 29 '12 at 12:20
  • http://i47.tinypic.com/2ngye85.png, no output.. nothing. Unlike other deprecated functions. – Adi Jun 29 '12 at 12:25
  • @Adnan Shammout: a short test has shown me right now that `split()` works on PHP 5.3.9, at least when used in a basic way. – Walter Tross Jun 29 '12 at 12:27
  • @WalterTross, that's very weird. Any PHP.ini option that forces deprecated functions not work? – Adi Jun 29 '12 at 12:28
  • 2
    @Adnan Shammout: yes, it is the `E_STRICT` in `error_reporting`. It is not included in `E_ALL` for PHP < 5.4, and anyhow it is probably not to be set for legacy code. It can also be switched off and on at runtime when entering and leaving legacy code, if needed. – Walter Tross Jun 29 '12 at 12:38
  • ... but this cannot be the whole story, because enabling `E_STRICT` on PHP 5.3.9 I get warnings in the log, but `split()` still works – Walter Tross Jun 29 '12 at 12:53

4 Answers4

5

If you really can't change the code you've got, how about creating wrappers for the new functions that have the same specification as the deprecated function? So in other words, you create a new function that calls the deprecated function but takes in the arguments of the old function. Might work...

Ben
  • 59,328
  • 35
  • 82
  • 105
4

You have to fix them to use the corresponding API that replaces the deprecated API. The deprecated API is deprecated for a reason.

nhahtdh
  • 52,949
  • 15
  • 113
  • 149
  • Exactly. It depends on precisely why the function was deprecated. – David Schwartz Jun 29 '12 at 12:03
  • But it's a very old project, so not possible to change in all the pages. – gopivignesh.m Jun 29 '12 at 12:04
  • 1
    @gv-me: If you are paid for it, then you must do it even if you don't like it. If this is personal project, then you can do as Ben suggested - but it is better to use the new API if you have decided to use the newer version of PHP. – nhahtdh Jun 29 '12 at 12:06
3

Deprecated functions are deprecated for a reason. You should either keep your distribution of PHP at an older release version, or upgrade and update the functions that are marked as deprecated. You should do the right thing and update your functions to those used in the newer versions of PHP. PHP4 stopped development in 2008, which means you really should've upgraded a long time ago.

If you're on Linux, Regexxer might be of some use to update all your files in one go.

Bojangles
  • 91,543
  • 47
  • 160
  • 197
3

The right thing to do is fix your code. PHP4 reached end of life 4 years ago and is not supported any more. I'm sure there exists a large number of dangerous bugs in PHP4 which will never be fixed.

The situation you are in now is called technical debt. You will need to repay the debt sooner or later.

You can add to your technical debt by reimplementing the old functions yourself, but that will make the code even harder to maintain in the future. Everything you do in your code base right now will probably need to be reimplemented from scratch once you've fixed the deprecated code. You can therefore choose to continue adding functions to the deprecated code (and increase the debt) or bringing the code into 2012 and repaying your debt entirely before going ahead and adding anything new.

Writing code is not hard or time-consuming. You should be able to find streamlined ways to fix the deprecated code. I'm sure you and your team may be able to solve most or all the deprecated code in a couple of days if you are focused on that only. In comparison, consider how much time it will take to implement even the simplest functions in a spaghetti-like code base.

Emil Vikström
  • 84,510
  • 15
  • 132
  • 168
  • Ouch, I missed the php4 tag when I wrote my comment about not updating, fixing is definitely the way to go... – jeroen Jun 29 '12 at 12:14