2

I'm working on a PHP Class, one of the required fields for the Class is (DropoffType) The answer to that is REGULARPICKUP. Can I write this inside the class and put "=" to the REGULARPICKUP?

Example:

protected $DropoffType = 'REGULARPICKUP';
PeeHaa
  • 71,436
  • 58
  • 190
  • 262

1 Answers1

3

Sure you can

class MyClass
{
    protected $DropoffType = 'REGULARPICKUP';
}

or do it in the constructor (this depends on your specific case whether this is the way to go):

class MyClass
{
    protected $DropoffType;

    public function __construct($Dropofftype = 'REGULARPICKUP')
    {
        $this->DropoffType = $Dropofftype;
    }
}

Or if you have a set function:

class MyClass
{
    protected $DropoffType;

    public function setDropoffType($Dropofftype = 'REGULARPICKUP')
    {
        $this->DropoffType = $Dropofftype;
    }
}
PeeHaa
  • 71,436
  • 58
  • 190
  • 262