What should I put into classes and what stuff I shouldnt?

Posted by jpjp on Stack Overflow See other posts from Stack Overflow or by jpjp
Published on 2010-05-27T20:09:42Z Indexed on 2010/05/27 20:21 UTC
Read the original article Hit count: 152

Filed under:
|
|

I am learning about classes right now in PHP and their examples are like..

class table { //makes a table
    private $tag ;
    function Begin($border=0, $align="center", $width='100%', $cellpadding=2, 
        $cellspacing=2, $class='', $id='', $bgcolor='', $style='') {
        $this->tag = '<table ' ;
        if ($align)              $this->tag .= 'align="' . $align . '" ' ;
        if ($width)              $this->tag .= 'width="' . $width . '" ' ;
        if ($border > 0)         $this->tag .= 'border="' . $border . '" ' ;
        if ($cellpadding > 0)     $this->tag .= 'cellpadding="' . $cellpadding . '" ' ;
        if ($cellspacing > 0)     $this->tag .= 'cellspacing="' . $cellspacing . '" ' ;
        if ($class)              $this->tag .= 'class="' . $class . '" ' ;
        if ($id)                  $this->tag .= 'id="' . $id . '" ' ;
        if ($bgcolor)              $this->tag .= 'bgcolor="' . $bgcolor . '" ' ;
        if ($style)              $this->tag .= 'style="' . $style . '" ' ;
        $this->tag .= ">" ;
        return $this->tag ;
    }

Then you just instantiate it and make a table by

$table =new table;
$table->$table($border=2, $align='center', etc);

Should I be coding like this where html, css are in classes? i feel making tables and forms this way is more confusing then actually just typing . Should I only put like validation, getting data from db, and the logic stuff in classes?

What should I use classes for and not?

© Stack Overflow or respective owner

Related posts about php

Related posts about oop