public function up()
 {
     $obj = new Teste();
     $obj->setName(System::$PARAMS['name'])->setXpto(System::$PARAMS['xpto']);
     if ($obj->update('id = ' . System::$PARAMS['id'])) {
         echo 'Update success!';
     }
 }
Beispiel #2
0
 public function cadastraTestes($testes, $msg)
 {
     // E impedimentos, por preguiça do programador
     global $mysqli;
     $res = $mysqli->prepare("DELETE FROM teste WHERE id_exercicio=?");
     $res->bind_param('i', $this->id);
     $res->execute();
     $ok = true;
     for ($i = 0, $c = 0; $i < sizeof($testes[1]); $i++) {
         $j = $i + 1;
         if (!empty($testes[1][$i])) {
             $c++;
             $T = new Teste();
             $ok = $ok and $T->create($this->id, $j, $testes[0][$i], $testes[1][$i], $testes[2][$i]);
         }
     }
     if (!$ok) {
         $msg .= "<p>Falha ao cadastrar os testes!</p>";
     } else {
         $msg .= " com {$c} testes. ";
     }
     $res = $mysqli->prepare("DELETE FROM proibido WHERE id_exercicio=?");
     $res->bind_param('i', $this->id);
     $res->execute();
     $ok = true;
     for ($i = 0; $i < sizeof($testes[3]); $i++) {
         if ($testes[3][$i]) {
             $T = new Proibidos();
             $ok = $ok and $T->create($testes[3][$i], $this->id);
         }
     }
     if (!$ok) {
         $msg .= "<p>Falha ao cadastrar os impedimentos!</p>";
     }
     $msg .= "Pr&oacute;ximos passos: <ul>\n\t\t\t<li><a href='exercicio.php?exerc={$this->id}'>Teste</a> se a corre&ccedil;&atilde;o funciona</li><li><a href='cadastra.php?exerc={$this->id}'>Edite</a> as defini&ccedil;&otilde;es deste exerc&iacute;cio</li><li>Determine o <a href='prazos.php'>prazo</a> de entrega</li></ul>";
     return $msg;
 }
<html>
<body>
<?php 
class Teste
{
    function Saudacao()
    {
        echo "Oi, pessoal";
    }
}
$objeto = new Teste();
//$objeto se torna uma instancia da classe teste
$objeto->Saudacao();
?>
</body>
</html> 
Beispiel #4
0
function test()
{
    $books = Teste::all();
    echo $books->toJson();
}
Beispiel #5
0
<?php

/**
 * Created by PhpStorm.
 * User: marco
 * Date: 01/07/16
 * Time: 12:08
 */
require 'vendor/autoload.php';
class Teste extends \Illuminate\Database\Eloquent\Model
{
    use \Microsistec\DbParser\Propertify;
    protected $table = 'properties';
}
$capsule = new Illuminate\Database\Capsule\Manager();
$capsule->addConnection(['driver' => 'mysql', 'host' => 'localhost', 'database' => 'betasci_db', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'options' => [PDO::ATTR_CASE => PDO::CASE_LOWER]]);
$capsule->bootEloquent();
/**
 * @var Teste $macarena
 */
$macarena = Teste::first();
var_dump($macarena->toArray());
                // gera um erro se não for um array
                echo "Parâmetro passado não é um array: " . $user . ".<br/>";
            }
        } else {
            if ($numParametros == 3) {
                // caso a função receba 3 parâmetros, supõe-se
                // que eles sejam 'id', 'nome' e 'email' respectivamente
                // insere usuário no sistema
                echo "Usuário inserido com sucesso.<br/>";
                echo "ID: " . func_get_arg(0) . "<br/>";
                echo "NOME: " . func_get_arg(1) . "<br/>";
                echo "EMAIL: " . func_get_arg(2) . "<br/>";
            } else {
                // se o número de parâmetros for diferente de
                // 1 e 3, um erro é gerado.
                echo "Quantidade de parâmetros incorreta.<br/>";
                echo "Parâmetros recebidos: " . func_num_args();
            }
        }
    }
}
// crio um objeto da classe Teste
$objTeste = new Teste();
// insiro um usuário passando um array com todos os dados
$objTeste->insertUser(array("id" => 1, "nome" => "Pedro Padron", "email" => "padronaaargh.com.br"));
echo "<br/>";
// insiro um usuário fornecendo cada atributo como um parâmetro
$objTeste->insertUser(2, "George W. Bush", "jackasswhitehouse.gov");
echo "<br/>";
// isso gerará um erro, pois foram passados apenas dois parâmetros
$objTeste->insertUser(2, "Tony Blair");
Beispiel #7
0
     } elseif (!empty($id) and isset($imp[$i])) {
         echo htmlspecialchars($imp[$i]->getPalavra());
     }
     echo "'></td></tr>";
 }
 echo "</table>";
 echo "<input type='hidden' id='nimp' name='nimp' value='{$nimp}'>";
 echo "<button type=\"submit\" name=\"submit\" value=\"addnimp\">+</button>";
 echo "<h3>Testes</h3>";
 echo "<br>N&uacute;mero de testes:&nbsp;&nbsp;";
 echo "<input type=\"text\" name=\"ntestes\" value=\"" . $ntestes . "\">&nbsp;";
 echo "<button type=\"submit\" name=\"submit\" value=\"alterar\">alterar</button>";
 echo "<table class='Cadastra'><tr><td><center><b>Ordem</b></center></td><td><center><b>Peso</b></center></td><td><center><b>Condi&ccedil;&atilde;o</b></center></td><td><center><b>Dica</b></center></td></tr>\n";
 for ($i = 0; $i < $ntestes; $i++) {
     if (!empty($id)) {
         $T = new Teste($id, $i + 1);
     }
     echo "<tr>";
     echo "<td><center>" . ($i + 1) . "</center></td>";
     echo "<td><input type='text' name='peso[]' value='";
     if (isset($_POST['peso'][$i])) {
         echo $_POST['peso'][$i];
     } elseif (!empty($id) and $T->peso()) {
         echo $T->peso();
     } else {
         echo 1;
     }
     echo "'></td><td><input class='long' type='text' name='condicao[]' value=\"";
     if (isset($_POST['condicao'][$i])) {
         echo htmlspecialchars($_POST['condicao'][$i]);
     } elseif (!empty($id)) {
Beispiel #8
0
<?php

class GerenciadorSequence
{
    public static $criado = array();
    public static $setado = array();
}
class Teste
{
    public function adicionar($valor)
    {
        GerenciadorSequence::$criado[] = $valor;
    }
}
$teste = new Teste();
$teste->adicionar("dfs");
$teste->adicionar("sfdsf");
echo "<pre>";
print_r(GerenciadorSequence::$criado);
echo "</pre>";
$teste->adicionar("dfs");
$teste->adicionar("sfdsf");
echo "<pre>";
print_r(GerenciadorSequence::$criado);
echo "</pre>";
GerenciadorSequence::$criado = array_unique(GerenciadorSequence::$criado);
echo "<pre>";
print_r(GerenciadorSequence::$criado);
echo "</pre>";
<?php

//class InvalidArgumentException extends Exception {}
class Teste
{
    public function imprime($string)
    {
        if (!is_string($string)) {
            throw new InvalidArgumentException('Esperava uma string!');
        }
        if (empty($string)) {
            throw new Exception('String está vazia!');
        }
        echo $string;
    }
}
$teste = new Teste();
// usando inteiro
try {
    $teste->imprime(127);
} catch (InvalidArgumentException $iae) {
    echo $iae->getMessage();
}
// usando string vazia
try {
    $teste->imprime('');
} catch (Exception $e) {
    echo $e->getMessage();
}