Advertisement
Guest User

Untitled

a guest
May 10th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 17.38 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Clase de trabajo sql.
  4.  *
  5.  * @author Abraham Cruz Sustaita (abraham.sustaita@gmail.com)
  6.  * @access Private
  7.  * @version 1.0.0
  8.  * @package Core
  9.  * @todo Fix CoreDB for only let one instance of the class.
  10.  *
  11.  * Clase que facilita el trabajo sql usando métodos que retornan los datos necesarios como tablas en la BD, campos, flags de los campos.
  12.  *
  13.  * Ejemplo de uso:
  14.  * $db = new Db ( null, 'test' );
  15.  *
  16.  * Select simple
  17.  * $db->select('testaa','id,name',array('and','id|=|1'));
  18.  * print_r($db->result);
  19.  *
  20.  * Select con función q
  21.  * $db->q('select name from testaa');
  22.  * print_r($db->res->fetch());
  23.  * while($row = $db->res->fetch())
  24.  *  print_r($row);
  25.  * $db->q('select name from testaa');  
  26.  * echo $db->fetchOne();
  27.  *
  28.  * Insert simple
  29.  * echo $db->insert ( 'testaa', 'name=\'algo\'' );
  30.  *
  31.  * Update
  32.  * echo $db->insert ( 'testaa', 'name=\'ponle algo111\', Id=99','id=99' );
  33.  *
  34.  *
  35.  */
  36. class Core_Db extends Core_Db_Singleton implements Core_Gral {
  37.     /**
  38.      * Constructor que solo permite una instancia de la clase para evitar multiples conecciones a la base
  39.      *
  40.      * @param string $host
  41.      * @param string $db
  42.      * @param string $user
  43.      * @param string $pass
  44.      * @param string $engine
  45.      * @return Object
  46.      */
  47.     public function __construct($host = null, $db = null, $user = null, $pass = null, $engine = null) {
  48.         if (! parent::$instance) {
  49.             parent::__construct ( $host, $db, $user, $pass, $engine );
  50.         } else {
  51.             return parent::$instance;
  52.         }
  53.         return false;
  54.     }
  55.     /**
  56.      * Evita el clonado del objeto
  57.      *
  58.      */
  59.     public function __clone() {
  60.         trigger_error ( 'Clone is not allowed.', E_USER_ERROR );
  61.     }
  62.     /**
  63.      * Crea métodos en tiempo de ejecución
  64.      *
  65.      * @param string $method
  66.      * @param mixed $args
  67.      */
  68.     public function __call($method, $args) {
  69.         //TODO Load methods on the fly
  70.     }
  71.     /**
  72.      * Evita error fatal al hacer echo $obj
  73.      *
  74.      * @return string
  75.      */
  76.     public function __toString() {
  77.         return '';
  78.     }
  79. }
  80. /**
  81.  * Clase de trabajo sql.
  82.  *
  83.  */
  84. class Core_Db_Singleton extends PDO {
  85.     /**
  86.      * Objeto con datos de las consultas sql
  87.      *
  88.      * @var Object
  89.      */
  90.     public $data;
  91.     /**
  92.      * Array con resultado de consultas sql
  93.      *
  94.      * @var array
  95.      */
  96.     public $result;
  97.     /**
  98.      * String que contiene un arreglo xml
  99.      *
  100.      * @var string
  101.      */
  102.     public $xml;
  103.     /**
  104.      * String que contiene una tabla xls
  105.      *
  106.      * @var string
  107.      */
  108.     public $xls;
  109.     /**
  110.      * Define si se agregegará ND a los xml armados
  111.      *
  112.      * @var bool
  113.      */
  114.     public $nd = true;
  115.     /**
  116.      * Objeto PDO con query
  117.      *
  118.      * @var Object
  119.      */
  120.     protected $res;
  121.     /**
  122.      * Tabla de última consulta sql
  123.      *
  124.      * @var string
  125.      */
  126.     protected $_table = null;
  127.     /**
  128.      * Número de página
  129.      *
  130.      * @var int
  131.      */
  132.     protected $_page = null;
  133.     /**
  134.      * Contraseña de Base de Datos
  135.      *
  136.      * @var string
  137.      */
  138.     protected $_user = USER;
  139.     /**
  140.      * Password de base de datos
  141.      *
  142.      * @var string
  143.      */
  144.     protected $_pass = PASSWORD;
  145.     /**
  146.      * Host
  147.      *
  148.      * @var string
  149.      */
  150.     protected $_host = HOST;
  151.     /**
  152.      * Base de datos
  153.      *
  154.      * @var string
  155.      */
  156.     protected $_db = DB;
  157.     /**
  158.      * Tipo de motor sql
  159.      *
  160.      * @var string
  161.      */
  162.     protected $_engine = 'mysql';
  163.     /**
  164.      * String con el query
  165.      *
  166.      * @var string
  167.      */
  168.     protected $_sql = null;
  169.     /**
  170.      * Propiedades a las que no se podrá acceder mediante su contenido
  171.      *
  172.      * @var array
  173.      */
  174.     private $_private = array ('_private' => true );
  175.     /**
  176.      * Propiedades que no podrán ser seteadas
  177.      *
  178.      * @var array
  179.      */
  180.     private $_notSet = array ('_private' => true, '_notSet' => true );
  181.     /**
  182.      * Objeto con funciones
  183.      *
  184.      * @var Object
  185.      */
  186.     private $_functions;
  187.     /**
  188.      * Instancia de la clase para solo usar una instancia
  189.      *
  190.      * @var Object
  191.      */
  192.     protected static $instance;
  193.     //Métodos públicos
  194.     /**
  195.      * Select que regresa un array asociativo con los datos arrojados por la consulta sql.
  196.      *
  197.      * @param string $table
  198.      * @param string $data
  199.      * @param mixed $where
  200.      * @param int $limit
  201.      * @param int $page
  202.      * @param string $order
  203.      */
  204.     public function select($table, $data = null, $where = null, $limit = null, $page = 1, $order = null) {
  205.         unset ( $this->_sql );
  206.         unset ( $this->res );
  207.         $data = ($data) ? $data : '*';
  208.         $this->_table = $table;
  209.         $this->_page = $page;
  210.         $q = 'SELECT SQL_CALC_FOUND_ROWS ' . $data . ' FROM ';
  211.         $q .= $table . ' ';
  212.         $q .= ($where) ? $this->_setWhere ( $where ) : '';
  213.         $q .= ($order) ? ' ORDER BY ' . $order : '';
  214.         $q .= ($limit) ? ' LIMIT ' . (($page - 1) * $limit) . ',' . $limit : '';
  215.         $this->_sql = $q;
  216.         try {
  217.             $this->res = $this->query ( $q );
  218.             if (! is_object ( $this->res ))
  219.                 throw new PDOException ( );
  220.         } catch ( PDOException $e ) {
  221.             $this->saveLogErr ( $e );
  222.             exit ();
  223.         }
  224.         $this->setFetch ();
  225.         $aryData = array ();
  226.         $count = 0;
  227.         while ( $ary = $this->res->fetch () ) {
  228.             $aryData [] = $ary;
  229.             ++ $count;
  230.         }
  231.         $this->result = $aryData;
  232.         return $count;
  233.     }
  234.     /**
  235.      * Ejecuta el query que este guardado en memoria y lo guarda en el array. Devuelve el número de rows
  236.      *
  237.      * @return int
  238.      */
  239.     public function asArray() {
  240.         $aryData = array ();
  241.         $count = 0;
  242.         while ( $ary = $this->res->fetch () ) {
  243.             $aryData [] = $ary;
  244.             ++ $count;
  245.         }
  246.         $this->result = $aryData;
  247.         return $count;
  248.     }
  249.     /**
  250.      * Deprecated.
  251.      * Ejecuta el query que este guardado en memoria y lo guarda en el array. Devuelve el número de rows
  252.      *
  253.      * @return int
  254.      */
  255.     public function personalized() {
  256.         $this->asArray ();
  257.     }
  258.     /**
  259.      * Prepara un query para ser usado
  260.      *
  261.      * @param string $q
  262.      */
  263.     public function q($q) {
  264.         unset ( $this->_sql );
  265.         unset ( $this->res );
  266.         $this->_sql = $q;
  267.         $qS = str_replace ( "\n", ' ', $q );
  268.         $aryQS = explode ( ' ', $qS );
  269.         foreach ( $aryQS as $key => $txt ) {
  270.             $txt = str_replace ( ' ', '', $txt );
  271.             if (strtoupper ( $txt ) == 'FROM') {
  272.                 $this->_table = $aryQS [$key + 1];
  273.                 break;
  274.             }
  275.         }
  276.         try {
  277.             $this->res = $this->query ( $q );
  278.             if (! is_object ( $this->res ))
  279.                 throw new PDOException ( );
  280.         } catch ( PDOException $e ) {
  281.             $this->saveLogErr ( $e );
  282.             exit ();
  283.         }
  284.         $this->setFetch ();
  285.     }
  286.     /**
  287.      * Regresa el único valor obtenido por el método select
  288.      *
  289.      * @return mixed
  290.      */
  291.     public function fetchOne() {
  292.         $ary = $this->res->fetch ();
  293.         $aryKeys = array_keys ( $ary );
  294.         $ret = $ary [$aryKeys [0]];
  295.         return $ret;
  296.     }
  297.     /**
  298.      * Método que hace inserción a la BD.
  299.      *
  300.      * Se le pasan como parámetros la tabla, los datos, el where (en forma de array opcional: array ('tipo', 'field|condicion|valor', 'field|condicion|valor')),
  301.      * y el límite (int opcional).
  302.      * Los tipos de where es tipo: 'AND', 'OR', 'PERSONALIZED'
  303.      * Los tipos de condicion son: =, >=, <=, BETWEEN, IN, NOT IN.  En caso de ser BETWEEN el tercer campo despues de | es
  304.      * ('condicion inicial') and ('condicion final')
  305.      * Regresa el id insertado o true en caso de ser update
  306.      *
  307.      * @param string $table
  308.      * @param string $data
  309.      * @param array $where
  310.      * @param int $limit
  311.      * @return int
  312.      */
  313.     public function insert($table, $data, $where = null, $limit = null) {
  314.         $q = ($where) ? 'UPDATE ' : 'INSERT ';
  315.         $q .= $table . ' SET ' . $data;
  316.         $q .= ($where) ? ' WHERE ' . $where : '';
  317.         $q .= ($limit) ? ' LIMIT ' . $limit : '';
  318.         //echo $q; exit;
  319.         unset ( $this->_sql );
  320.         unset ( $this->res );
  321.         $this->_sql = $q;
  322.         try {
  323.             $this->res = $this->query ( $q );
  324.             if (! is_object ( $this->res ))
  325.                 throw new PDOException ( );
  326.         } catch ( PDOException $e ) {
  327.             echo '<br>El siguiente insert no es válido:</br>
  328.             <strong>' . $q . '</strong><br />';
  329.             $this->saveLogErr ( $e );
  330.             return false;
  331.         }
  332.         $this->res->fetch ();
  333.         $id = 'SELECT LAST_INSERT_ID()';
  334.         $idQ = $this->query ( $id );
  335.         $idA = $idQ->fetch ();
  336.         return ($where != null) ? true : $idA ['LAST_INSERT_ID()'];
  337.     }
  338.     /**
  339.      * Método que agrega al objeto data los campos de la tabla.
  340.      *
  341.      * @param string $table
  342.      */
  343.     public function fields($table = null) {
  344.         unset ( $this->_sql );
  345.         unset ( $this->res );
  346.         $table = (! empty ( $this->_table )) ? $this->_table : (($table) ? $table : null);
  347.         if ($table != null) {
  348.             //echo 'SHOW FULL COLUMNS FROM ' . $table ;
  349.             $this->q ( 'SHOW FULL COLUMNS FROM ' . $table );
  350.             $fields = array ();
  351.             while ( $field = $this->res->fetch () ) {
  352.                 $fields [] = $field;
  353.                 //print_r ($field);
  354.             }
  355.             $this->data->fields = $fields;
  356.         }
  357.     }
  358.     /**
  359.      * Revisa si la tabla se encuentra en la base de datos.  Si la encuentra, lista los campos que tiene.
  360.      *
  361.      * @param string $table
  362.      * @return int
  363.      */
  364.     public function checkTable($table = null) {
  365.         $table = ($table == null) ? $this->_table : $table;
  366.         $this->listTables ();
  367.         foreach ( $this->data->tables as $tableExist ) {
  368.             if ($tableExist == $table) {
  369.                 $this->fields ();
  370.                 return true;
  371.                 break;
  372.             }
  373.         }
  374.         return false;
  375.     }
  376.     /**
  377.      * Método que busca el total de la última consulta sql SIN limites
  378.      *
  379.      * @return int
  380.      */
  381.     public function getTot() {
  382.         unset ( $this->_sql );
  383.         unset ( $this->res );
  384.         $this->q ( 'SELECT FOUND_ROWS()' );
  385.         $ret = $this->fetchOne ();
  386.         $this->data->tot = $ret;
  387.         return $ret;
  388.     }
  389.     /**
  390.      * Regresa un xml formado con el nombre de la tabla en la que se ejecuto la consulta
  391.      *
  392.      * @return string
  393.      */
  394.     public function xml() {
  395.         header ( "Content-type: application/xml" );
  396.         $xml = '<query>';
  397.         foreach ( $this->result as $aryResult ) {
  398.             $xml .= '<' . $this->_table . ' ';
  399.             foreach ( $aryResult as $field => $data ) {
  400.                 $xml .= ' ' . $field . '="' . $this->_clean ( $data ) . '" ';
  401.             }
  402.             $xml .= '/>';
  403.         }
  404.         if ($this->nd == true) {
  405.             $xml .= '<' . $this->_table . ' ';
  406.             foreach ( $aryResult as $field => $data ) {
  407.                 $xml .= ' ' . $field . '="ND" ';
  408.             }
  409.             $xml .= '/>';
  410.         }
  411.         $xml .= '</query>';
  412.         $this->xml = $xml;
  413.         return $xml;
  414.     }
  415.     /**
  416.      * Genera un archivo de excel con la consulta previa
  417.      *
  418.      * @return string
  419.      */
  420.     public function xls($aryHead = null, $headers = true) {
  421.         //echo 'tsss';
  422.         if ($headers) {
  423.             $this->_functions->excel ( $this->_table . '.xls' );
  424.         }
  425.         $xls = '<table>
  426.         <tr>';
  427.         $aryHead = ($aryHead) ? $aryHead : array_keys ( $this->result [0] );
  428.         foreach ( $aryHead as $head ) {
  429.             $xls .= '<td>' . utf8_decode ( $head ) . '</td>';
  430.         }
  431.         $xls .= '</tr>';
  432.         foreach ( $this->result as $aryFields ) {
  433.             $xls .= '<tr>';
  434.             foreach ( $aryFields as $field ) {
  435.                 $xls .= '<td>' . utf8_decode ( $field ) . '</td>';
  436.             }
  437.             $xls .= '</tr>';
  438.         }
  439.         $xls .= '</table>';
  440.         $this->xls = $xls;
  441.         return $xls;
  442.     }
  443.     /**
  444.      * Método que obtiene la llave primaria de una tabla
  445.      *
  446.      * @param string $table
  447.      */
  448.     public function getPrimary($table = null) {
  449.         $this->fields ( $table );
  450.         foreach ( $this->data->fields as $aryField ) {
  451.             if ($aryField ['Key']) {
  452.                 $this->data->primary = $aryField ['Field'];
  453.                 break;
  454.             }
  455.         }
  456.     }
  457.     //Métodos privados
  458.     /**
  459.      * Genera un string where a partir de un array.
  460.      *
  461.      * El primer valor del array es el tipo de where - and, or, like y personal - y los demás son el where dividido por | teniendo tres valores:
  462.      * campo|condicion|valor.  Si la condición es between el valor deberá ser dos fechas en formato sql.
  463.      *
  464.      * @param array $aryWhere
  465.      * @return string
  466.      */
  467.     private function _setWhere($aryWhere) {
  468.         $sql = '';
  469.         if (is_string ( $aryWhere )) {
  470.             return ' WHERE ' . $aryWhere;
  471.         }
  472.         //print_r($aryWhere);
  473.         if (count ( $aryWhere ) > 0) {
  474.             $sql .= 'WHERE ';
  475.             if (strtoupper ( $aryWhere [0] ) == "LIKE") {
  476.                 unset ( $aryWhere [0] );
  477.                 if (strtoupper ( $aryWhere [1] ) == "AND") {
  478.                     $and = " AND ";
  479.                 } else {
  480.                     $and = " OR ";
  481.                 }
  482.                 unset ( $aryWhere [1] );
  483.                 $totWhere = count ( $aryWhere );
  484.                 $iW = 1;
  485.                 foreach ( $aryWhere as $k => $j ) {
  486.                     if ($iW == $totWhere) {
  487.                         $sql .= " " . $k . " LIKE '%" . $j . "%' ";
  488.                     } else {
  489.                         $sql .= " " . $k . " LIKE '%" . $j . "%' " . $and;
  490.                     }
  491.                     $iW ++;
  492.                 }
  493.             } else if (strtoupper ( $aryWhere [0] ) == "AND" || strtoupper ( $aryWhere [0] ) == "OR") {
  494.                 $and = (strtoupper ( $aryWhere [0] ) == 'AND') ? 'AND' : 'OR';
  495.                 unset ( $aryWhere [0] );
  496.                 $totWhere = count ( $aryWhere );
  497.                 $iW = 1;
  498.                 foreach ( $aryWhere as $k => $j ) {
  499.                     $whereB = explode ( "|", $j );
  500.                     if ($iW == $totWhere) {
  501.                         if (strtoupper ( $whereB [1] ) == 'LIKE') {
  502.                             $sql .= " " . $whereB [0] . ' ' . $whereB [1] . " '%" . $whereB [2] . "%' ";
  503.                         } else if (strtoupper ( $whereB [1] ) == 'IN' || strtoupper ( $whereB [1] ) == 'NOT IN' || strtoupper ( $whereB [1] ) == 'BETWEEN')
  504.                             $sql .= " " . $whereB [0] . ' ' . $whereB [1] . " " . $whereB [2] . " ";
  505.                         else
  506.                             $sql .= " " . $whereB [0] . $whereB [1] . "'" . $whereB [2] . "' ";
  507.                     } else {
  508.                         if (strtoupper ( $whereB [1] ) == 'IN' || strtoupper ( $whereB [1] ) == 'NOT IN' || strtoupper ( $whereB [1] ) == 'BETWEEN') {
  509.                             $sql .= " " . $whereB [0] . ' ' . $whereB [1] . " " . $whereB [2] . "  $and ";
  510.                         } else if (strtoupper ( $whereB [1] ) == 'LIKE')
  511.                             $sql .= " " . $whereB [0] . ' ' . $whereB [1] . " '%" . $whereB [2] . "%'  $and ";
  512.                         else
  513.                             $sql .= " " . $whereB [0] . $whereB [1] . "'" . $whereB [2] . "' $and ";
  514.                     }
  515.                     $iW ++;
  516.                 }
  517.             } else if (empty ( $aryWhere [0] )) {
  518.                
  519.                 $whereB = explode ( "|", $aryWhere [1] );
  520.                 if (strtoupper ( $whereB [1] ) == 'IN' || strtoupper ( $whereB [1] ) == 'NOT IN' || strtoupper ( $whereB [1] ) == 'LIKE' || strtoupper ( $whereB [1] ) == 'BETWEEN')
  521.                     $sql .= " " . $whereB [0] . ' ' . $whereB [1] . " " . $whereB [2] . " ";
  522.                 else
  523.                     $sql .= " " . $whereB [0] . $whereB [1] . "'" . $whereB [2] . "' ";
  524.             } else if (strtoupper ( $aryWhere [0] ) == "PERSONAL") {
  525.                 unset ( $aryWhere [0] );
  526.                 $sql .= $aryWhere [1];
  527.             }
  528.         }
  529.         return $sql;
  530.     }
  531.     /**
  532.      * Intenta conección a BD o guarda error
  533.      *
  534.      */
  535.     protected function _connect() {
  536.         try {
  537.             parent::__construct ( "$this->_engine:host=$this->_host;dbname=$this->_db", $this->_user, $this->_pass );
  538.         } catch ( PDOException $e ) {
  539.             Core_Db::saveLogErr ( $e );
  540.         }
  541.         try {
  542.             $this->query ( "SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'" );
  543.         } catch ( PDOException $e ) {
  544.             Core_Db::saveLogErr ( $e );
  545.         }
  546.     }
  547.     /**
  548.      * Define el tipo de fetch a usar, assoc por default
  549.      *
  550.      * @param string $mode
  551.      */
  552.     protected function setFetch($mode = 'FETCH_ASSOC') {
  553.         try {
  554.             if (! is_object ( $this->res )) {
  555.                 throw new PDOException ( );
  556.             }
  557.             if ($mode == 'FETCH_ASSOC')
  558.                 $this->res->setFetchMode ( PDO::FETCH_ASSOC );
  559.         } catch ( PDOException $e ) {
  560.             $this->saveLogErr ( $e );
  561.         }
  562.     }
  563.     /**
  564.      * Método que guarda el log de errores de conecciones y demás
  565.      *
  566.      * @param PDOException $e
  567.      * @param bool $show
  568.      */
  569.     private function saveLogErr($e, $show = true) {
  570.         $err_repo = error_reporting ();
  571.         error_reporting ( $err_repo );
  572.         if ($show == true && $err_repo != 0) {
  573.             echo '<p>Se ha detectado el siguiente error y es imposible continuar:<br />
  574.         <strong>' . $e->getMessage () . '</strong>
  575.         </p>
  576.         La traza para el error es la siguiente:<br />
  577.         ';
  578.             echo '<strong>' . str_replace ( "\n", '<br />' . "\n", $e->getTraceAsString () ) . '</strong>';
  579.             echo '
  580.         <br />
  581.         <br>La linea del error fue:<br />
  582.         <strong>' . $e->getLine () . '</strong><br />
  583.         El query fue: ' . $this->_sql . '
  584.         ';
  585.         }
  586.         //TODO Guardar en archivo
  587.     }
  588.     protected function _clean($data) {
  589.         $aDirty = array ();
  590.         $aDirty ['&'] = '&';
  591.         foreach ( $aDirty as $dirty => $clean ) {
  592.             $data = str_replace ( $dirty, $clean, $data );
  593.         }
  594.         return $data;
  595.     }
  596.     /**
  597.      * Método que lista las tablas de la base de datos
  598.      *
  599.      */
  600.     protected function listTables() {
  601.         $q = "SHOW TABLES";
  602.         unset ( $this->_sql );
  603.         unset ( $this->res );
  604.         $this->_sql = $q;
  605.         try {
  606.             $this->res = parent::query ( $q );
  607.         } catch ( PDOException $e ) {
  608.             print_r ( $e );
  609.         }
  610.         if (! is_object ( $this->res ))
  611.             echo 'El siguiente query no es válido: ' . $q;
  612.         $this->setFetch ();
  613.         while ( $list = $this->res->fetch () ) {
  614.             $this->data->tables [] = $list ['Tables_in_' . $this->_db];
  615.         }
  616.     }
  617.    
  618.     //Métodos mágicos
  619.     /**
  620.      * Constructor de la clase; recibe como parametros host, db, user, pass y engine. Por default son localhost, null, root, null y mysql
  621.      *
  622.      * @param string $host
  623.      * @param string $db
  624.      * @param string $user
  625.      * @param string $pass
  626.      * @param string $engine
  627.      */
  628.     public function __construct($host = null, $db = null, $user = null, $pass = null, $engine = null) {
  629.         $this->_user = ($user) ? $user : $this->_user;
  630.         $this->_pass = ($pass) ? $pass : $this->_pass;
  631.         $this->_host = ($host) ? $host : $this->_host;
  632.         $this->_db = ($db) ? $db : $this->_db;
  633.         $this->_engine = ($engine) ? $engine : $this->_engine;
  634.         $this->data = new stdClass ( );
  635.         $this->_connect ();
  636.         $this->_functions = new Core_Functions ( );
  637.     }
  638.     /**
  639.      * Método __get, recibe como parámetro la propiedad a obtener
  640.      *
  641.      * @param string $prop
  642.      * @return mixed
  643.      */
  644.     public function __get($prop) {
  645.         $ret = null;
  646.         if ($this->$prop && ! isset ( $this->_private [$prop] ))
  647.             $ret = $this->$prop;
  648.         return $ret;
  649.     }
  650.     /**
  651.      * Método __set, recibe la variable y el valor a setear
  652.      *
  653.      * @param string $prop
  654.      * @param mixed $var
  655.      */
  656.     public function __set($prop, $var) {
  657.         if (! isset ( $this->_notSet [$prop] ))
  658.             $this->$prop = $var;
  659.     }
  660.     public function __destruct() {
  661.         unset ( $this );
  662.     }
  663.  
  664. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement