Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default classes... why?

    why would i use a class in php, and how do i use a class in php?


    Sticks Guest

  2. Similar Questions and Discussions

    1. new to php classes
      Hi everyone, I am new to using classes in PHP development. Can someone tell me if it's possible to use a class inside a class. I am developing...
    2. two classes
      how can I call class b method b, from class a method a ?
    3. Classes
      do you get an error-message? which? maybe you use var $id = array(); instead of var $id; ciao SVEN Patrik Fomin wrote:
    4. First Go at Classes
      So, here I am, I've been programming PHP for 6 years, and have never gotten into classes. Well, I finally decided to take the plunge, and here's my...
    5. ASP Classes vs COM
      For the majority of my work, I just use plain ASP. On the rare occasion that I am doing something intensive that does require user interaction I...
  3. #2

    Default classes... why?

    why would i use a class in php, and how do i use a class in php?


    Sticks Guest

  4. #3

    Default Re: classes... why?

    On Tue, 12 Aug 2003 17:34:19 +1000, Sticks wrote:
    > why would i use a class in php, and how do i use a class in php?
    Simplistic: Classes make it easier to write "reusable" code

    For more information about classes in php... read the manual (there are some
    little examples on how to use them)
    also search google for OO and php or OOPS and php (Object Oriented)
    sotto Guest

  5. #4

    Default Re: classes... why?

    On Tue, 12 Aug 2003 17:34:19 +1000, Sticks wrote:
    > why would i use a class in php, and how do i use a class in php?
    Simplistic: Classes make it easier to write "reusable" code

    For more information about classes in php... read the manual (there are some
    little examples on how to use them)
    also search google for OO and php or OOPS and php (Object Oriented)
    sotto Guest

  6. #5

    Default Re: classes... why?

    With total disregard for any kind of safety measures "Sticks"
    <strat11@hotmail.com> leapt forth and uttered:
    > why would i use a class in php, and how do i use a class in php?
    >
    >
    Read this: [url]http://sitepointforums.com/showthread.php?threadid=59898[/url]

    --
    There is no signature.....
    Phil Roberts Guest

  7. #6

    Default Re: classes... why?

    With total disregard for any kind of safety measures "Sticks"
    <strat11@hotmail.com> leapt forth and uttered:
    > why would i use a class in php, and how do i use a class in php?
    >
    >
    Read this: [url]http://sitepointforums.com/showthread.php?threadid=59898[/url]

    --
    There is no signature.....
    Phil Roberts Guest

  8. #7

    Default Re: classes... why?

    Ian.H [dS] wrote:
    > -----BEGIN PGP SIGNED MESSAGE-----
    > Hash: SHA1
    >
    > Whilst lounging around on Tue, 12 Aug 2003 10:32:40 +0200, Warstar
    > <warstar@NSA.com> amazingly managed to produce the following with
    > their Etch-A-Sketch:
    >
    >
    >>>why would i use a class in php, and how do i use a class in php?
    >>
    >>because it is great u can get more readable code and better
    >>security.
    >
    >
    >
    > How does using classes make things more secure than anything else?
    >
    > <?php
    > class foo {
    > function bar($string) {
    > system($string);
    > return;
    > }
    > }
    >
    > foo::bar('rm -rf /');
    > ?>
    >
    >
    > How is the above more secure than:
    >
    >
    > system('rm -rf /');
    >
    Because you would probably write checking code inside the class to stop
    the user from making stupid mistakes like that.

    Kevin Thorpe Guest

  9. #8

    Default Re: classes... why?

    Ian.H [dS] wrote:
    > -----BEGIN PGP SIGNED MESSAGE-----
    > Hash: SHA1
    >
    > Whilst lounging around on Tue, 12 Aug 2003 10:32:40 +0200, Warstar
    > <warstar@NSA.com> amazingly managed to produce the following with
    > their Etch-A-Sketch:
    >
    >
    >>>why would i use a class in php, and how do i use a class in php?
    >>
    >>because it is great u can get more readable code and better
    >>security.
    >
    >
    >
    > How does using classes make things more secure than anything else?
    >
    > <?php
    > class foo {
    > function bar($string) {
    > system($string);
    > return;
    > }
    > }
    >
    > foo::bar('rm -rf /');
    > ?>
    >
    >
    > How is the above more secure than:
    >
    >
    > system('rm -rf /');
    >
    Because you would probably write checking code inside the class to stop
    the user from making stupid mistakes like that.

    Kevin Thorpe Guest

  10. #9

    Default Re: classes... why?

    > But that's no different from:
    >
    > $string = 'rm -rf /';
    > if ($string != 'rm -rf /') {
    > system($string);
    > }
    >
    >
    > is it?
    >
    > My point was just that whatever code you use, beit classes, functions
    > or "inline", it's all as secure as you make it, there is no real
    > security advantages / disadvantages of using / not using classes if
    > you code correctly from the outset.. but if you feel that because
    > code is written "inline" it doesn't need checking / validating.. only
    > when within a class, then the mind boggles.
    Methinks my answer was a little short and didn't explain my meaning
    properly. In the case of you, Ian, I realise this is a grandmother-egg
    situation, but I'll include a full explanation for the original poster.

    If I have an application which deals with something like purchase orders
    I would have a database table to hold them. At this point I can write my
    php scripts to create, modify and write them. If I only need a couple of
    short scripts then I would probably include all my error checking in
    these scripts.

    However, if the application starts to grow larger the amount of checking
    performed in each script starts to become unwieldy. There's also a
    danger that I might alter the underlying structure of a purchase order
    and fail to update the error checking in every script in the
    application. This can easily lead to damaged records in the database.
    The situation is even worse if someone else has written custom scripts
    which I know nothing about.

    At this point all handling of purchase orders should be encapsulated
    within a class (or library of functions) which contain a definitive set
    of error and consistency checks for dealing with a purchase order. If I
    alter the structure or rules for a purchase order I change one class
    library to reflect this. Incorrectly written scripts will then fail
    (hopefully gracefully) without damaging records in the database.

    This also helps to protect me from any odd implementation gotchas which
    I've forgotten about in the intervening years since I wrote the
    application. Writing programs is one thing, maintaining them over a long
    period of time (some over 10 years now) is a completely different game.
    Anything which helps to clarify your original thinking or stops you
    shooting yourself in the foot is of prime importance.




    Kevin Thorpe Guest

  11. #10

    Default Re: classes... why?

    > But that's no different from:
    >
    > $string = 'rm -rf /';
    > if ($string != 'rm -rf /') {
    > system($string);
    > }
    >
    >
    > is it?
    >
    > My point was just that whatever code you use, beit classes, functions
    > or "inline", it's all as secure as you make it, there is no real
    > security advantages / disadvantages of using / not using classes if
    > you code correctly from the outset.. but if you feel that because
    > code is written "inline" it doesn't need checking / validating.. only
    > when within a class, then the mind boggles.
    Methinks my answer was a little short and didn't explain my meaning
    properly. In the case of you, Ian, I realise this is a grandmother-egg
    situation, but I'll include a full explanation for the original poster.

    If I have an application which deals with something like purchase orders
    I would have a database table to hold them. At this point I can write my
    php scripts to create, modify and write them. If I only need a couple of
    short scripts then I would probably include all my error checking in
    these scripts.

    However, if the application starts to grow larger the amount of checking
    performed in each script starts to become unwieldy. There's also a
    danger that I might alter the underlying structure of a purchase order
    and fail to update the error checking in every script in the
    application. This can easily lead to damaged records in the database.
    The situation is even worse if someone else has written custom scripts
    which I know nothing about.

    At this point all handling of purchase orders should be encapsulated
    within a class (or library of functions) which contain a definitive set
    of error and consistency checks for dealing with a purchase order. If I
    alter the structure or rules for a purchase order I change one class
    library to reflect this. Incorrectly written scripts will then fail
    (hopefully gracefully) without damaging records in the database.

    This also helps to protect me from any odd implementation gotchas which
    I've forgotten about in the intervening years since I wrote the
    application. Writing programs is one thing, maintaining them over a long
    period of time (some over 10 years now) is a completely different game.
    Anything which helps to clarify your original thinking or stops you
    shooting yourself in the foot is of prime importance.




    Kevin Thorpe Guest

  12. #11

    Default Re: classes... why?

    On Tue, 12 Aug 2003 17:34:19 +1000, "Sticks" <strat11@hotmail.com>
    wrote:
    >why would i use a class in php, and how do i use a class in php?
    This is probably going to open a Pandora's Box, but after much playing
    around with PHP I have ended up doing procedural program design rather
    than object oriented.

    Granted, for complex applications it's going to be handy, but because
    PHP has no application level objects, setting any complex data
    structures and so on up is a bit of a nightmare because you have to do
    it at the start of every page - hardly ideal...

    kafooey Guest

  13. #12

    Default Re: classes... why?

    No application level objects? What about SRM?
    [url]http://www.vl-srm.net/index.php[/url]

    kafooey wrote:
    > On Tue, 12 Aug 2003 17:34:19 +1000, "Sticks" <strat11@hotmail.com>
    > wrote:
    >
    >
    >>why would i use a class in php, and how do i use a class in php?
    >
    >
    > This is probably going to open a Pandora's Box, but after much playing
    > around with PHP I have ended up doing procedural program design rather
    > than object oriented.
    >
    > Granted, for complex applications it's going to be handy, but because
    > PHP has no application level objects, setting any complex data
    > structures and so on up is a bit of a nightmare because you have to do
    > it at the start of every page - hardly ideal...
    >
    Louis-Philippe Huberdeau Guest

  14. #13

    Default Re: classes... why?

    "sotto" <junk@sotto.be> wrote in message
    news:pan.2003.08.12.07.52.02.309390@sotto.be...
    > On Tue, 12 Aug 2003 17:34:19 +1000, Sticks wrote:
    >
    > > why would i use a class in php, and how do i use a class in php?
    >
    > Simplistic: Classes make it easier to write "reusable" code
    >
    > For more information about classes in php... read the manual (there are
    some
    > little examples on how to use them)
    > also search google for OO and php or OOPS and php (Object Oriented)
    Does PHP support inheritance and the like?

    I too never understood the point of classes but due to HAVING to learn about
    C# which is entirely OO, I've found them to be VERY usefull. I'll certainly
    be porting my new found OOP knowledge to my PHP work.

    BTW - my advice to anybody who doesn't know what classes are for; go and
    learn now! The concept can be quite difficult to grasp, but once you have,
    you'll wish you learnt earlier.

    Regards,

    Nathan


    treefroginometry Guest

  15. #14

    Default Re: classes... why?

    "sotto" <junk@sotto.be> wrote in message
    news:pan.2003.08.12.07.52.02.309390@sotto.be...
    > On Tue, 12 Aug 2003 17:34:19 +1000, Sticks wrote:
    >
    > > why would i use a class in php, and how do i use a class in php?
    >
    > Simplistic: Classes make it easier to write "reusable" code
    >
    > For more information about classes in php... read the manual (there are
    some
    > little examples on how to use them)
    > also search google for OO and php or OOPS and php (Object Oriented)
    Does PHP support inheritance and the like?

    I too never understood the point of classes but due to HAVING to learn about
    C# which is entirely OO, I've found them to be VERY usefull. I'll certainly
    be porting my new found OOP knowledge to my PHP work.

    BTW - my advice to anybody who doesn't know what classes are for; go and
    learn now! The concept can be quite difficult to grasp, but once you have,
    you'll wish you learnt earlier.

    Regards,

    Nathan


    treefroginometry Guest

  16. #15

    Default Re: classes... why?

    With total disregard for any kind of safety measures
    "treefroginometry" <info@skunkbag.antispam.co.uk> leapt forth and
    uttered:
    > Does PHP support inheritance and the like?
    >
    PHP supports inheritence yes. It's missing a number of structures
    in PHP4 such as abstract classes, interfaces, private/protected
    methods and properties and the like though. These will all be part
    of PHP5 however.
    > I too never understood the point of classes but due to HAVING to
    > learn about C# which is entirely OO, I've found them to be VERY
    > usefull. I'll certainly be porting my new found OOP knowledge to
    > my PHP work.
    >
    It's a state of mind that takes a good while to establish. My
    housemate is a PHP beginner and I had to walk him through the usage
    of basic functions as he hadn't even grasped that fundamental
    concept. OOP takes it to a whole new level.
    > BTW - my advice to anybody who doesn't know what classes are
    > for; go and learn now! The concept can be quite difficult to
    > grasp, but once you have, you'll wish you learnt earlier.
    Very true.

    --
    There is no signature.....
    Phil Roberts Guest

  17. #16

    Default Re: classes... why?

    With total disregard for any kind of safety measures
    "treefroginometry" <info@skunkbag.antispam.co.uk> leapt forth and
    uttered:
    > Does PHP support inheritance and the like?
    >
    PHP supports inheritence yes. It's missing a number of structures
    in PHP4 such as abstract classes, interfaces, private/protected
    methods and properties and the like though. These will all be part
    of PHP5 however.
    > I too never understood the point of classes but due to HAVING to
    > learn about C# which is entirely OO, I've found them to be VERY
    > usefull. I'll certainly be porting my new found OOP knowledge to
    > my PHP work.
    >
    It's a state of mind that takes a good while to establish. My
    housemate is a PHP beginner and I had to walk him through the usage
    of basic functions as he hadn't even grasped that fundamental
    concept. OOP takes it to a whole new level.
    > BTW - my advice to anybody who doesn't know what classes are
    > for; go and learn now! The concept can be quite difficult to
    > grasp, but once you have, you'll wish you learnt earlier.
    Very true.

    --
    There is no signature.....
    Phil Roberts Guest

  18. #17

    Default Re: classes... why?

    treefroginometry wrote:
    > Does PHP support inheritance and the like?

    [url]http://www.php.net/manual/en/language.oop.php[/url]




    Brian Rodenborn
    Default User Guest

  19. #18

    Default Re: classes... why?

    treefroginometry wrote:
    > Does PHP support inheritance and the like?

    [url]http://www.php.net/manual/en/language.oop.php[/url]




    Brian Rodenborn
    Default User Guest

  20. #19

    Default Re: classes... why?

    In article <Xns93D5EA60A2442philroberts@216.196.97.132>,
    Phil Roberts <philrob@HOLYflatnetSHIT.net> wrote:
    > With total disregard for any kind of safety measures
    > "treefroginometry" <info@skunkbag.antispam.co.uk> leapt forth and
    > uttered:
    >
    > > Does PHP support inheritance and the like?
    > >
    >
    > PHP supports inheritence yes.
    True. Multiple inheritance is not, however, supported.

    --
    CC
    CC Zona Guest

  21. #20

    Default Re: classes... why?

    In article <Xns93D5EA60A2442philroberts@216.196.97.132>,
    Phil Roberts <philrob@HOLYflatnetSHIT.net> wrote:
    > With total disregard for any kind of safety measures
    > "treefroginometry" <info@skunkbag.antispam.co.uk> leapt forth and
    > uttered:
    >
    > > Does PHP support inheritance and the like?
    > >
    >
    > PHP supports inheritence yes.
    True. Multiple inheritance is not, however, supported.

    --
    CC
    CC Zona Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139