public function __construct($array = null) { parent::__construct(); if ($array != null) { foreach ($array as $row => $v) { $this->{$row} = $v; } } }
public function saveNew() { $this->secret = $this->generateSecret(); $this->date = date('Y-m-d H:i:s'); $this->official = 0; $this->status = 0; if (empty($this->url)) { $this->url = ''; } return parent::saveNew(); }
public function saveNew() { $this->id = ''; $user = new User(); $user = $user->get($this->uid); if (!$user) { throw new Exception('user not found'); } $this->country = $user->country; $id = parent::saveNew(); return $id; }
<?php class BasicClass { const CLASS_CONSTANT = 12.7; public function multiply($x) { return $x * self::CLASS_CONSTANT; } } echo BasicClass::CLASS_CONSTANT . '<br />' . PHP_EOL; $inst = new BasicClass(); echo $inst->multiply(3) . '<br />' . PHP_EOL;
public function __construct($name) { self::$staticVariable = $name; }
if (isset($this)) { echo '$this is defined ('; echo get_class($this); echo ")<br />"; } else { echo "\$this is not defined.<br />"; } } } class B { function boo() { A::foo(); } } $a = new BasicClass(); $a->foo(); A::foo(); $b = new B(); $b->boo(); B::boo(); ?>
public function saveNew() { $this->id = ''; $this->quality = 1; $this->pendingUnits = 0; $this->money = 0; $this->maxEmployees = self::MIN_EMPLOYEES; $user = new User(); $user = $user->get($this->uid); if (!$user) { throw new Exception('user not found'); } if ($user->gold < self::CREATION_COST) { throw new Exception('no gold enough'); } $id = parent::saveNew(); if ($id) { $user->gold -= self::CREATION_COST; $user->save(); } return $id; }
/** * creates a new user * * @return mixed (uid or false) */ public function saveNew() { $this->status = self::STATUS_PENDING; $this->gold = 0; $this->xp = 0; $this->language = 'en'; $q = "select `id` from `" . $this->table . "` where `email`='" . $this->email . "' OR `nick`='" . $this->nick . "' LIMIT 1"; $rows = Service::getDB()->query($q); if (sizeof($rows) > 0) { return false; } return parent::saveNew(); }
<?php class BasicClass { private $var1; protected $var2; public $var3; public function __construct($var) { $this->var1 = $var; $this->var2 = $var; $this->var3 = $var; } public function doubleVar3() { $this->var3 = $this->var3 . ' ' . $this->var3; } public function getVar1() { return $this->var1; } } $inst = new BasicClass('foo'); echo $inst->getVar1() . '<br />' . PHP_EOL; $inst->doubleVar3(); echo $inst->var3;