Is this class of mine okay?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wren9
Forum Newbie
Posts: 9
Joined: Sat May 23, 2009 1:50 am

Is this class of mine okay?

Post by wren9 »

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


I just created a class with multidimensional array in it, please look below,

Code: Select all

 
<?php
//scraping class
 
class casting
{
    public $jobs = array("casting_id" => array(
        "job_id" => 0, 
        "listed_on" => '', 
        "expiration" => '', 
        "location" => '', 
        "gender" => '', 
        "age" => '', 
        "categories" => '',         
        "union" => '', 
        "rate" => '', 
        "email" => '', 
        "description" => ''));
    
    function __construct() {
    
    }
 
    function __destruct() {
 
    }
    
    function setJobs($casting_id, $job_id, $listed_on, $expiration, $location, $gender, $age, $categories, $union, $rate, $email, $description) {
        $this->jobs[]['job_id'] = $casting_id;
        $this->jobs[]['listed_on'] = $job_id;
        $this->jobs[]['listed_on'] = $listed_on;
        $this->jobs[]['expiration'] = $expiration;
        $this->jobs[]['location'] = $expiration;
        $this->jobs[]['']['gender'] = $gender;
        $this->jobs[]['age'] = $age;
        $this->jobs[]['categories'] = $categories;
        $this->jobs[]['union'] = $union;
        $this->jobs[]['rate'] = $rate;
        $this->jobs[]['email'] = $email;
        $this->jobs[]['description'] = $description;
    }
    
    function setJobs($casting_id, $job_id, $listed_on, $expiration, $location, $gender, $age, $categories, $union, $rate, $email, $description) {   
        return $this->jobs[]['job_id'];
        return $this->jobs[]['listed_on'];
        return $this->jobs[]['listed_on'];
        return $this->jobs[]['expiration'];
        return $this->jobs[]['location'];
        return $this->jobs[]['']['gender'];
        return $this->jobs[]['age'] = $age;
        return $this->jobs[]['categories'];
        return $this->jobs[]['union'];
        return $this->jobs[]['rate'];
        return $this->jobs[]['email'];
        return $this->jobs[]['description'];    
    }
    
}
 
$newcasting = new casting();
?>
 
Can you check my class please, specially the accessing, assignment and returning the array.
Please note the array is two dimensional, i used the array for temporary replacement for mysql.

Can you check those please, thanks in advance.


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Is this class of mine okay?

Post by pickle »

- I would suggest turning a job into a class itself. You could then have setListedOn(), setExpiration() etc methods.
- Change setJobs() to addJob() to more accurately reflect the purpose of the function.
- Why do you have 2 declarations of setJobs()?
- When adding a job, set the array index to the id of the job. That will make it MUCH easier to delete a job if that ever comes up.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Is this class of mine okay?

Post by Darhazer »

You have multiple returns in the function. The result is that only the first line is executed.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Is this class of mine okay?

Post by Christopher »

I am guessing that there is a database table full of jobs/roles somewhere. This class probably provides an interface to that table. Take a look at the Table Data Gateway pattern.
(#10850)
Post Reply