PHP

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • functions classes

    7 answers - 261 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Can anyone tell me if it is relatively an easy process for an experienced
    coder (not me) to convert a php script to mainly functions/classes.
    I have my own script that i would like to make more streamlined as it is
    becoming very difficult to work with.
  • No.1 | | 402 bytes | |

    25/08/06, Peter Lauri <lists (AT) dwsasia (DOT) comwrote:

    It should not be to big of a problem if you can set your mind into
    thinking
    about functions and objects instead of a step by step script. Then just
    cut
    it in pieces and your are done :)

    Agreed. If it puts you on the good foot, send an extract from your script
    and I will give you an indicator of where to start.
  • No.2 | | 567 bytes | |

    Hi Bigmark,

    Bigmark schrieb am 25.08.2006 11:39:
    Can anyone tell me if it is relatively an easy process for an experienced
    coder (not me) to convert a php script to mainly functions/classes.
    I have my own script that i would like to make more streamlined as it is
    becoming very difficult to work with.

    it's not impossible, but can take a lot of time to pick the script to
    pieces and get it converted to a script (ore more coherent scripts) with
    functions and/or classes.
    It depends on the script itself.

    Greets
    Mourad
  • No.3 | | 2489 bytes | |

    Bigmark,

    I have been involved in the evolution of the development process and
    architecture called functional normalization. I do intend to post some
    detail on this at funkifunctions.blogspot.com very soon.

    Anyhow, using this method might help you some what. The trick being to
    look through your script and see if the same thing is being done in more
    than one place. For example, if you find a piece of code that converts
    a string into a URL and that piece of code is REPEATED through thes
    script, then place that code in a function and replace the instance of
    the code with function calls.

    a period of time you will see more and more of your code turn into
    functions. this process has started you will be able to predict to
    some extent what new pieces of code could be re-used in this way and
    hence write them as functions also.

    This approach has proved to be extremely successful in advancing the
    careers and coding practices of developers inside and contractors to the
    project network (www.project-network.com).

    If you would like, I am very happy to take a script from you and convert
    it over to functions. I will also let you know when more material on FN
    is posted to the blogsphere.

    As for classes. I would recommend avoiding thinking about these yet.
    Function level re-use is a better start discipline that class level
    re-use IMH I know this is an contentious issue. Having been an avid
    programmer for many years I have evolved away from this, other people
    have different views (yes really, I did a lot of work with
    Java/Weblogic/C++/iTCL etc etc etc - please don't flame - not interested!).

    For more thoughts on what I don't like about :

    Best wishes and good luck

    AJ

    Mourad Boulahboub wrote:
    Hi Bigmark,

    Bigmark schrieb am 25.08.2006 11:39:
    >Can anyone tell me if it is relatively an easy process for an experienced
    >coder (not me) to convert a php script to mainly functions/classes.
    >I have my own script that i would like to make more streamlined as it is
    >becoming very difficult to work with.
    >>


    it's not impossible, but can take a lot of time to pick the script to
    pieces and get it converted to a script (ore more coherent scripts) with
    functions and/or classes.
    It depends on the script itself.

    Greets
    Mourad
  • No.4 | | 873 bytes | |

    Friday 25 August 2006 04:39, Bigmark wrote:
    Can anyone tell me if it is relatively an easy process for an experienced
    coder (not me) to convert a php script to mainly functions/classes.
    I have my own script that i would like to make more streamlined as it is
    becoming very difficult to work with.

    That really depends on the nature of the code. I've some code I have to work
    with now that is built around dumping all kinds of stuff into the global
    namespace, even from functions. If I ever manage convince the author what an
    insanely bad idea that is, it will still be hell to fix because of the way
    it's built.

    Most code probably isn't quite that bad, though. Your code could already
    break down into functions quite nicely, or it could be easier to just start
    from scratch. No way to tell without seeing the code.
  • No.5 | | 1920 bytes | |

    Larry,

    I have hit similar global names space issues in the past and it is a
    pain in the behind!

    remedial method that can get it stable enough to start to work on is
    to stick the whole messy lot into classes (NT BJECTS!) and then the
    global name space becomes the local namespace (ie $MyVar becomes
    $GarbageCode::MyVar).

    you have done this, you can put accessors functions around the
    class local variables. This means that all new code calls the accessors.

    $newVar=GarbageCode::GetMyVar();

    Thus, if you improve the internal representation of the garbage code,
    code outside the old garbage code will no longer be impacted by the change.

    From an FN point of view, you are reducing the access to the variable
    to a single function point rather than many function points distributed
    throughout the code base.

    Cheers

    AJ

    PS - if you knew all this before hand - please accept my apologies :-)

    Larry Garfield wrote:
    Friday 25 August 2006 04:39, Bigmark wrote:
    >Can anyone tell me if it is relatively an easy process for an experienced
    >coder (not me) to convert a php script to mainly functions/classes.
    >I have my own script that i would like to make more streamlined as it is
    >becoming very difficult to work with.


    That really depends on the nature of the code. I've some code I have to work
    with now that is built around dumping all kinds of stuff into the global
    namespace, even from functions. If I ever manage convince the author what an
    insanely bad idea that is, it will still be hell to fix because of the way
    it's built.

    Most code probably isn't quite that bad, though. Your code could already
    break down into functions quite nicely, or it could be easier to just start
    from scratch. No way to tell without seeing the code.
  • No.6 | | 2615 bytes | |

    I don't know what I was on when I wrote the previous post!

    In php you cannot create static class variables in this way (doh) or at
    least I never have managed. So when faced the this problem I replace
    what in C++ would be a class variable with a class function

    comme ca:

    class MyClass
    {
    function MyVar($val = null)
    {
    static $datum;
    if(is_null($val))
    {
    return $datum;
    }
    $dataum=$val;
    }

    }

    I definitely need more coffee!

    AJ

    Alex Turner wrote:
    Larry,

    I have hit similar global names space issues in the past and it is a
    pain in the behind!

    remedial method that can get it stable enough to start to work on is
    to stick the whole messy lot into classes (NT BJECTS!) and then the
    global name space becomes the local namespace (ie $MyVar becomes
    $GarbageCode::MyVar).

    you have done this, you can put accessors functions around the
    class local variables. This means that all new code calls the accessors.

    $newVar=GarbageCode::GetMyVar();

    Thus, if you improve the internal representation of the garbage code,
    code outside the old garbage code will no longer be impacted by the change.

    From an FN point of view, you are reducing the access to the variable
    to a single function point rather than many function points distributed
    throughout the code base.

    Cheers

    AJ

    PS - if you knew all this before hand - please accept my apologies :-)

    Larry Garfield wrote:
    >Friday 25 August 2006 04:39, Bigmark wrote:

    Can anyone tell me if it is relatively an easy process for an
    experienced
    coder (not me) to convert a php script to mainly functions/classes.
    I have my own script that i would like to make more streamlined as it is
    becoming very difficult to work with.
    >>

    >That really depends on the nature of the code. I've some code I have
    >to work with now that is built around dumping all kinds of stuff into
    >the global namespace, even from functions. If I ever manage convince
    >the author what an insanely bad idea that is, it will still be hell to
    >fix because of the way it's built.
    >>

    >Most code probably isn't quite that bad, though. Your code could
    >already break down into functions quite nicely, or it could be easier
    >to just start from scratch. No way to tell without seeing the code.
    >>
  • No.7 | | 1232 bytes | |

    Sat, 2006-08-26 at 12:49 +0100, Alex Turner wrote:
    I don't know what I was on when I wrote the previous post!

    In php you cannot create static class variables in this way (doh) or at
    least I never have managed. So when faced the this problem I replace
    what in C++ would be a class variable with a class function

    comme ca:

    class MyClass
    {
    function MyVar($val = null)
    {
    static $datum;
    if(is_null($val))
    {
    return $datum;
    }
    $dataum=$val;
    }

    }

    I definitely need more coffee!

    Talking about coffee your above code could use some. Try this:

    <?php

    class MyClass
    {
    function MyVar( $val=null )
    {
    static $datum;

    if( $val null )
    {
    return $datum;
    }

    $datum = $val;
    }
    }

    ?>

    But also I'd recommend fixing the the problem whereby you
    can't set $datum to the null value, otherwise you may run
    into unexpected issues down the road.

    <?php

    class MyClass
    {
    function MyVar( $val=null, $set=false )
    {
    static $datum;

    if( $set false )
    {
    return $datum;
    }

    $datum = $val;
    }
    }

    ?>

    Cheers,
    Rob.

Re: functions classes


max 4000 letters.
Your nickname that display:
In order to stop the spam: 4 + 3 =
QUESTION ON "PHP"

EMSDN.COM