Class Olivier extends Human

neigedhiver Messages postés 2480 Date d'inscription jeudi 30 novembre 2006 Statut Membre Dernière intervention 14 janvier 2011 - 3 nov. 2010 à 02:42
neigedhiver Messages postés 2480 Date d'inscription jeudi 30 novembre 2006 Statut Membre Dernière intervention 14 janvier 2011 - 3 nov. 2010 à 12:02
<?php
/*
 * Copyright (C) 2010 - Neigedhiver
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

namespace Animal;

class Human {
const STATE_PITIFUL = 'pitiful';
const STATE_TIRED = 'tired';
const STATE_THINKING = 'thinking';
const STATE_NO_SLEEPING_FOR_2_DAYS = 'almost dead';
}

/**
 * This is me
 * @author olivier
 *
 */
class Olivier extends Human {

/**
 * This is private == secret
 * @var $age int
 */
private $age = 33;

/**
 * Oh ! Really ?
 * @var boolean
 */
protected $geek = TRUE;

/**
 * The time I go to bed (UnixTimestamp)
 * @TODO : Use DateTime
 * @var $timeWentToBed int
 */
private $timeWentToBed;

/**
 * Naturraly, no one can change this value !!
 * @return boolean
 */
public function isGeek() {
return $geek;
}

public function __sleep() {
switch ($this -> state) {
case Human::STATE_THINKING:
case Human::STATE_PITIFUL:
$this -> waitBeforeSleep();
break;
case Human::STATE_NO_SLEEPING_FOR_2_DAYS:
$this -> closeEyes('45min', array($this -> openEyes(), $this -> waitBeforeSleep()));
break;
}
}

public function __wakeUp() {
if ($this -> hasAppoitment()) {
$this -> openEyes();
$this -> standUp();
$this -> state = Human::STATE_PITIFUL & Human::STATE_TIRED;
$this -> increaseAdrenaline('max');
$this -> mode = 'hurry';
}
else {
if ($this -> canEarAlarmClock()) {
$this -> shutTheFuckUp($this -> alarmClock);
}
elseif ($this -> mode !== 'dreaming') {
$this -> dream();
}
}
}

/**
 * May I ever be able to sleep in less than 2 hours ?
 */
private function waitBeforeSleep() {
static $wait = 0;
// Can't really be 0...
0 $wait && $wait mt_rand(1,6);
// @TODO : use DateInterval and DatePeriod
while(time() > $this -> timeWentToBed + 3600*$wait) {
$this -> think() or $this -> worry();
// Every 30 minutes...
if ((time() - $this -> timeWentToBed) % 30 == 0) {
$this -> openEyes();
}
if ($wait > 2 && time() > $this -> timeWentToBed + 3600) {
$this -> standUp();
$this -> wear($this -> clothes);
$this -> computer -> screen -> powerOn();
$this -> writeDumbCode();
}
}
// Of course...
if ($wait > 2) {
$this -> state = Human::STATE_PITIFUL;
}
$wait = 0;
}

/**
 * I wish I could live my dreams
 */
private function dream() {
static $dreams = array('superHeroe', 'meetGirls', 'fly', 'sleeping', 'rich', 'famous', 'writeMovies');
$this -> dream = mt_rand(0, count($dreams));
}

/**
 * An important activity in my life
 * @param $movie
 */
private function watchMovie(Movie $movie) {
$this -> mode = 'lazy';
if ($movie -> isBoring && $this -> eyesStatus === 'open') {
$this -> closeEyes(new Flock(5000));
}
if ($movie -> isReallyBoring && $this -> state = Human::STATE_PITIFUL) {
$this -> dream();
}
// Damn !!
Delay::forget($movie, strtotime('+2 months'));
}

/**
 * Yesssss :)
 * @param $flock How many sheeps are there ?
 */
private function closeEyes(Flock $flock) {
$count = 0;
foreach ($flock as $sheep) {
$count++;
}
}

/**
 * Does it really work ?
 * @return boolean
 */
private function canEarAlarmClock() {
$probability $this -> state Human::NO_SLEEP_FOR_2_DAYS ? 0.2 : 0.6;
return Random::headsOrTails($probability);
}
}


?>



--
Neige

Souvent la réponse à votre question se trouve dans la doc. Commencez par là ;)

2 réponses

TychoBrahe Messages postés 1309 Date d'inscription samedi 31 janvier 2009 Statut Membre Dernière intervention 5 juin 2013 12
3 nov. 2010 à 11:45
Salut,

<?php

include 'olivier.php';
$ol = new Animal\Olivier();
$sol = serialize($ol);

?>

Notice: Undefined property: Animal\Olivier::$state in /path/to/olivier.php on line 63

Notice: serialize(): __sleep should return an array only containing the names of instance-variables to serialize in /path/to/olivier_test.php on line 5

olivier.php contenant ta classe et olivier_test.php étant le code juste au dessus.
0
neigedhiver Messages postés 2480 Date d'inscription jeudi 30 novembre 2006 Statut Membre Dernière intervention 14 janvier 2011 19
3 nov. 2010 à 12:02
Arf, mince, c'est pour ça que je buggue tous les soirs dans mon lit...

--
Neige

Souvent la réponse à votre question se trouve dans la doc. Commencez par là ;)
0
Rejoignez-nous