Creating new team matches I have a class which creates a new match. My problem is that I am sure the code is unnecessary long and can get much improved (just keep in mind it is beginner level).

Specifically, I would like to know:


Can I change the below into 1 setter and 1 getter method?
I would like to use the rand() function for match ID can I do this inside the setter function of setMatchId or should it be done outside of the class?
When I upload the class to a db I assume I would need to create a new method and code the DB upload inside the method or should this be done outside of the class.




&lt;?php
class match{
private $matchId;
private $team1;
private $team2;
private $venue; 

function __construct($pMatchId, $pTeam1, $pTeam2, $pVenue){
    $this-&gt;matchId = $pMatchId;
    $this-&gt;team1 = $pTeam1;
    $this-&gt;team2 = $pTeam2;
    $this-&gt;venue = $pVenue;
}
    function setMatchId($pMatchId){
        $this-&gt;matchId = $pMatchId;

    }

    function getMatchId(){
        return $this-&gt;matchId;  

    }
    function setTeam1($pTeam1){
        $this-&gt;team1 = $pTeam1; 
    }
    function getTeam1(){
        return $this-&gt;team1;    

    }

    function setTeam2($pTeam2){
        $this-&gt;team2 = $pTeam2; 
    }
    function getTeam2(){
        return $this-&gt;team2;    

    }
    function setVenue($pVenue){
        $this-&gt;venue = $pVenue; 

    }
    function getVenue(){
        return $this-&gt;venue;    

    }

} // c;lass match

$x = new match("1", "Patriots", "Chargers", "Newlands");
echo $x-&gt;getMatchId();
echo'&lt;br /&gt;';
echo $x-&gt;getTeam1();
echo'&lt;br /&gt;';
echo $x-&gt;getTeam2();
echo'&lt;br /&gt;';
echo $x-&gt;getVenue();
?&gt;
Can I change the below into 1 setter and 1 getter method?


You could use magic getters and setters, but you probably shouldn't (see the top-rated answer in that question; additionally, with the primitive approach, you would make all your private fields accessible from the outside). 

You should also ask yourself if you even need setters. If the properties of the object never change after construction, you should make it immutable, as immutable objects are easier to handle (you know that they never change).


  I would like to use the rand() function for match ID can I do this inside the setter function of setMatchId or should it be done outside of the class?


You should not add a method setMatchId() that doesn't accept an argument, but just generates the id. Setters should set something, not generate something.

On the other hand, a method such as regenerateMatchId would be perfectly acceptable (although I'm not sure why you would want the id to be random). 


  When I upload the class to a db I assume I would need to create a new method and code the DB upload inside the method or should this be done outside of the Class


By "upload to the db", you mean save in the database? Basically, you would have three options:


add the "save to db" method to this class
create a MatchDAO which saves matches to the db
use an ORM such as doctrine


Misc


class names should ideally start with an upper-case letter (see for example PSR-1)
your indentation is off, as is your vertical whitespace
what does the p in your argument names stand for? It's unclear, I would just remove it.