Variable dans les classes php

Résolu/Fermé
matdev Messages postés 26 Date d'inscription mardi 19 mai 2009 Statut Membre Dernière intervention 6 janvier 2011 - 8 févr. 2010 à 10:56
matdev Messages postés 26 Date d'inscription mardi 19 mai 2009 Statut Membre Dernière intervention 6 janvier 2011 - 8 févr. 2010 à 11:26
Bonjour,

je rencontre actuellement un petit problème pour définir une variable étant un tableau contenant différentes valeur à utiliser en fonction d'un paramètre dans une classe php.

J'ai bien défini ma classe j'accède correctement à mes fonctions par contre j'utilise pour ces fonctions un paramètre me permettant de savoir la période sur laquelle ma fonction doit se concentrer.

Par rapport au paramètre passé à la fonction, je fais référence à un tableau pour compléter mes requetes sql.

Voici le tableau


$where=array(
        "J"=>" and created=now()",
        "J-1"=>" and created=subdate(now(),INTERVAL 1 DAY)",
        "S"=>" and week(created)=week(now()) and year(created)=year(now())",
        "S-1"=>" and week(created)=week(subdate(now(),INTERVAL 1 WEEK)) and year(created)=year(subdate(now(),INTERVAL 1 WEEK))",
        "M"=>" and month(created)=month(now()) and year(created)=year(now())",
        "M-1"=>" and month(created)=month(subdate(now(),INTERVAL 1 MONTH)) and year(created)=year(subdate(now(),INTERVAL 1 MONTH))",
        "M-2"=>" and month(created)=month(subdate(now(),INTERVAL 2 MONTH)) and year(created)=year(subdate(now(),INTERVAL 2 MONTH))",
        "T"=>" and quarter(created)=quarter(now()) and year(created)=year(now())",
        "T-1"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 1 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 1 QUARTER))",
        "T-2"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 2 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 2 QUARTER))",
        "T-3"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 3 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 3 QUARTER))",
        "A"=>" and year(created)=year(now())",
        "A-1"=>" and year(created)=year(subdate(now(),INTERVAL 1 YEAR))",
        "A-2"=>" and year(created)=year(subdate(now(),INTERVAL 2 YEAR))"
        );

Comment faire pour ne pas avoir à définir mon tableau dans chaque fonction mais de manière générale à ma classe php

J'ai essayé ceci mais je récupère null dans mon affichage de page.


<?php
class MyLib_Util
{
    
    var $where=array(
        "J"=>" and created=now()",
        "J-1"=>" and created=subdate(now(),INTERVAL 1 DAY)",
        "S"=>" and week(created)=week(now()) and year(created)=year(now())",
        "S-1"=>" and week(created)=week(subdate(now(),INTERVAL 1 WEEK)) and year(created)=year(subdate(now(),INTERVAL 1 WEEK))",
        "M"=>" and month(created)=month(now()) and year(created)=year(now())",
        "M-1"=>" and month(created)=month(subdate(now(),INTERVAL 1 MONTH)) and year(created)=year(subdate(now(),INTERVAL 1 MONTH))",
        "M-2"=>" and month(created)=month(subdate(now(),INTERVAL 2 MONTH)) and year(created)=year(subdate(now(),INTERVAL 2 MONTH))",
        "T"=>" and quarter(created)=quarter(now()) and year(created)=year(now())",
        "T-1"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 1 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 1 QUARTER))",
        "T-2"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 2 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 2 QUARTER))",
        "T-3"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 3 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 3 QUARTER))",
        "A"=>" and year(created)=year(now())",
        "A-1"=>" and year(created)=year(subdate(now(),INTERVAL 1 YEAR))",
        "A-2"=>" and year(created)=year(subdate(now(),INTERVAL 2 YEAR))"
        );

    
    public function comptaentres($type){
    
        Zend_Debug::dump($this->where[$type]);
    }



Merci pour votre aide

1 réponse

matdev Messages postés 26 Date d'inscription mardi 19 mai 2009 Statut Membre Dernière intervention 6 janvier 2011 5
8 févr. 2010 à 11:26
class MyLib_Util
{
	
	private static $where=array(
		"J"=>" and created=now()",
		"J-1"=>" and created=subdate(now(),INTERVAL 1 DAY)",
		"S"=>" and week(created)=week(now()) and year(created)=year(now())",
		"S-1"=>" and week(created)=week(subdate(now(),INTERVAL 1 WEEK)) and year(created)=year(subdate(now(),INTERVAL 1 WEEK))",
		"M"=>" and month(created)=month(now()) and year(created)=year(now())",
		"M-1"=>" and month(created)=month(subdate(now(),INTERVAL 1 MONTH)) and year(created)=year(subdate(now(),INTERVAL 1 MONTH))",
		"M-2"=>" and month(created)=month(subdate(now(),INTERVAL 2 MONTH)) and year(created)=year(subdate(now(),INTERVAL 2 MONTH))",
		"T"=>" and quarter(created)=quarter(now()) and year(created)=year(now())",
		"T-1"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 1 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 1 QUARTER))",
		"T-2"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 2 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 2 QUARTER))",
		"T-3"=>" and quarter(created)=quarter(subdate(now(),INTERVAL 3 QUARTER)) and year(created)=year(subdate(now(),INTERVAL 3 QUARTER))",
		"A"=>" and year(created)=year(now())",
		"A-1"=>" and year(created)=year(subdate(now(),INTERVAL 1 YEAR))",
		"A-2"=>" and year(created)=year(subdate(now(),INTERVAL 2 YEAR))"
	);

	public function comptaentres($type){
			Zend_Debug::dump(self::$where[$type]);
	}
0