IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Problème de classe avec PHP 5 ?


Sujet :

Langage PHP

  1. #1
    Membre actif

    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Septembre 2002
    Messages : 472
    Points : 262
    Points
    262
    Par défaut Problème de classe avec PHP 5 ?
    Bonjour,

    Je n'arrive pas à faire marcher mon code qui est pourtant tout simple...

    Fichier : image.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    <?php
         header("Content-type: image/png");
         include('Graphique.class.php');
         $MonGraphique = new Graphique(500,250);
         $MonGraphique->Courbe();
    ?>
    Fichier : Graphique.class.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
    <?php
         class Graphique
         {
               var $GraphiqueLargeur;
               var $GraphiqueHauteur;
               var $GraphiqueImage;
               var $GraphiqueCouleurNoir;
     
               public function __construct($largeur, $hauteur)
               {
                      $this->GraphiqueLargeur = $largeur;
                      $this->GraphiqueHauteur = $hauteur;
                      $this->GraphiqueImage = ImageCreate($this->GraphiqueLargeur, $this->GraphiqueHauteur);
                      $this->GraphiqueCouleurNoir = ImageColorAllocate($this->GraphiqueImage, 0, 0, 0);
                      ImageLine($this->GraphiqueImage, 0, 0, 0, $this->GraphiqueHauteur, $this->GraphiqueCouleurNoir);
    	          ImageLine($this->GraphiqueImage, 0, 0, $this->GraphiqueLargeur, 0, $this->GraphiqueCouleurNoir);
    	          ImageLine($this->GraphiqueImage, $this->GraphiqueLargeur-1, 0, $this->GraphiqueLargeur-1, $this->GraphiqueLargeur-1, $this->GraphiqueCouleurNoir);
    	          ImageLine($this->GraphiqueImage, 0, $this->GraphiqueHauteur-1, $this->GraphiqueLargeur-1, $this->GraphiqueHauteur-1, $this->GraphiqueCouleurNoir);
               }
     
               public function Courbe()
               {
                      ImagePng($this->GraphiqueImage);
               }
         }
    ?>
    Lorsque j'essai mon fichier "image.php", j'ai l'erreur suivante :
    GraphiqueLargeur = $largeur;
 $this->GraphiqueHauteur = $hauteur;
 $this->GraphiqueImage = ImageCreate($this->GraphiqueLargeur, $this->GraphiqueHauteur);
 $this->GraphiqueCouleurNoir = ImageColorAllocate($this->GraphiqueImage, 0, 0, 0);
 ImageLine($this->GraphiqueImage, 0, 0, 0, $this->GraphiqueHauteur, $this->GraphiqueCouleurNoir);
 ImageLine($this->GraphiqueImage, 0, 0, $this->GraphiqueLargeur, 0, $this->GraphiqueCouleurNoir);
 ImageLine($this->GraphiqueImage, $this->GraphiqueLargeur-1, 0, $this->GraphiqueLargeur-1, $this->GraphiqueLargeur-1, $this->GraphiqueCouleurNoir);
 ImageLine($this->GraphiqueImage, 0, $this->GraphiqueHauteur-1, $this->GraphiqueLargeur-1, $this->GraphiqueHauteur-1, $this->GraphiqueCouleurNoir);
 }
 
 public function Courbe()
 {
 ImagePng($this->GraphiqueImage);
 }
 }
?>
    Fatal error: Class 'Graphique' not found in D:\xxxxxxx\xxxx\xxx\xxxxx\image.php on line 4
    J'ai essayé d'écrire un code clair, je ne comprends pas pourquoi j'ai cette erreur ?

    Elle est sur cette ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $MonGraphique = new Graphique(500,250);
    C'est la première fois que j'utilise les classes, j'ai bien PHP 5 avec la dernière version de WAMP (Apache/2.0.58 (Win32) PHP/5.1.4) sous Windows XP.

    Merci d'avance pour votre aide,
    Mathieu
    Embarcadero RAD Studio XE / Microsoft Windows 7 Édition Intégrale (64 bits)

  2. #2
    Membre confirmé
    Inscrit en
    Mai 2002
    Messages
    673
    Détails du profil
    Informations forums :
    Inscription : Mai 2002
    Messages : 673
    Points : 624
    Points
    624
    Par défaut
    Je suis pas super callé en class PHP non plus, mais quand j'en utilise, je fait mon constructeur façon c++, donc

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    function Graphique($para1, $param2)
    au lieu de

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    function __construct($apra1, $param2)
    Je sais vraiment pas si ça fait une différence, mais a tout hazard ^^
    Si vous avez un message d'erreur, n'oubliez pas de le lire, la réponse à votre problème est surement dedans !

  3. #3
    Membre actif

    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Septembre 2002
    Messages : 472
    Points : 262
    Points
    262
    Par défaut
    Bonjour,

    Je viens d'essayer ta méthode mais mon problème reste inchangé...

    Si je mets tout dans le même fichier :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
     
    <?php
         header("Content-type: image/png");
         class Graphique
         {
               var $GraphiqueLargeur;
               var $GraphiqueHauteur;
               var $GraphiqueImage;
               var $GraphiqueCouleurBlanc;
               var $GraphiqueCouleurNoir;
     
               public function __construct($largeur, $hauteur)
               {
                      $this->GraphiqueLargeur = $largeur;
                      $this->GraphiqueHauteur = $hauteur;
                      $this->GraphiqueImage = ImageCreate($this->GraphiqueLargeur, $this->GraphiqueHauteur);
                      $this->GraphiqueCouleurNoir = ImageColorAllocate($this->GraphiqueImage, 0, 0, 0);
                      $this->GraphiqueCouleurBlanc = ImageColorAllocate($this->GraphiqueImage, 255, 255, 255);
                      ImageLine($this->GraphiqueImage, 0, 0, 0, $this->GraphiqueHauteur, $this->GraphiqueCouleurNoir);
    	          ImageLine($this->GraphiqueImage, 0, 0, $this->GraphiqueLargeur, 0, $this->GraphiqueCouleurNoir);
    	          ImageLine($this->GraphiqueImage, $this->GraphiqueLargeur-1, 0, $this->GraphiqueLargeur-1, $this->GraphiqueLargeur-1, $this->GraphiqueCouleurNoir);
    	          ImageLine($this->GraphiqueImage, 0, $this->GraphiqueHauteur-1, $this->GraphiqueLargeur-1, $this->GraphiqueHauteur-1, $this->GraphiqueCouleurNoir);
               }
     
               public function Courbe()
               {
                      ImagePng($this->GraphiqueImage);
               }
         }
     
         $MonGraphique = new Graphique(500,250);
         $MonGraphique->Courbe();
    ?>
    Il semble ne pas inclure le fichier de ma classe correctement...

    Comment dois-je faire pour mettre ma classe dans un fichier ?

    Merci,
    Mathieu
    Embarcadero RAD Studio XE / Microsoft Windows 7 Édition Intégrale (64 bits)

  4. #4
    Membre émérite
    Avatar de Nesmontou
    Homme Profil pro
    Architecte logiciel
    Inscrit en
    Septembre 2004
    Messages
    1 612
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Architecte logiciel
    Secteur : Finance

    Informations forums :
    Inscription : Septembre 2004
    Messages : 1 612
    Points : 2 969
    Points
    2 969
    Par défaut
    Salut, je viens de tester en faisant un copier/coller du code de ton premier post et ça marche nickel chez moi ; j'ai bien un rectangle noir à l'écran.

    Tes 2 fichiers (image.php et Graphique.class.php) sont bien dans le même répertoire ?
    Si vous ne pouvez expliquer un concept à un enfant de six ans, c'est que vous ne le comprenez pas complètement. Albert EINSTEIN

    F.A.Q. : Java, PHP, (X)HTML / CSS

    N'oubliez pas de cliquer sur le bouton Résolu en bas de page quand vous avez obtenu une solution à votre problème

  5. #5
    Membre actif

    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Septembre 2002
    Messages : 472
    Points : 262
    Points
    262
    Par défaut
    Bonjour,

    Oui, ils sont bien dans le même répertoire. Il y a un problèe avec l'include...

    Lorsque je mets tout dans le même fichier, çamarche aussi chez moi sans aucun soucis...

    C'est très étrange...

    Merci pour votre aide,
    Mathieu
    Embarcadero RAD Studio XE / Microsoft Windows 7 Édition Intégrale (64 bits)

  6. #6
    Membre actif

    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Septembre 2002
    Messages : 472
    Points : 262
    Points
    262
    Par défaut
    Bonjour,

    Ci-joint mes fichiers.

    Merci,
    Mathieu
    Fichiers attachés Fichiers attachés
    Embarcadero RAD Studio XE / Microsoft Windows 7 Édition Intégrale (64 bits)

  7. #7
    Membre actif

    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Septembre 2002
    Messages : 472
    Points : 262
    Points
    262
    Par défaut
    Bonjour,

    Je viens de me rendre compte en éditant le fichier avec notepad qu'il contenait plein de quote qui polluait le code...

    C'est réparé et ça marche

    J'ai jamais eu ce problème... Etrange...

    J'utilise tsWebEditor...

    Merci,
    Mathieu
    Embarcadero RAD Studio XE / Microsoft Windows 7 Édition Intégrale (64 bits)

  8. #8
    Expert éminent
    Avatar de sekaijin
    Homme Profil pro
    Urbaniste
    Inscrit en
    Juillet 2004
    Messages
    4 205
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 60
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Urbaniste
    Secteur : Santé

    Informations forums :
    Inscription : Juillet 2004
    Messages : 4 205
    Points : 9 127
    Points
    9 127
    Par défaut
    essais de charger qu ele fichier Graphique.class.php en mettant le niveau d'erreur à E_ALL
    je me demande s'il n'y a pas une erreur qui fait que ta classe n'est pas définie.

    GraphiqueLargeur = $largeur;
 $this->GraphiqueHauteur = $hauteur;
 $this->GraphiqueImage = ImageCreate($this->GraphiqueLargeur, $this->GraphiqueHauteur);
 $this->GraphiqueCouleurNoir = ImageColorAllocate($this->GraphiqueImage, 0, 0, 0);
 ImageLine($this->GraphiqueImage, 0, 0, 0, $this->GraphiqueHauteur, $this->GraphiqueCouleurNoir);
 ImageLine($this->GraphiqueImage, 0, 0, $this->GraphiqueLargeur, 0, $this->GraphiqueCouleurNoir);
 ImageLine($this->GraphiqueImage, $this->GraphiqueLargeur-1, 0, $this->GraphiqueLargeur-1, $this->GraphiqueLargeur-1, $this->GraphiqueCouleurNoir);
 ImageLine($this->GraphiqueImage, 0, $this->GraphiqueHauteur-1, $this->GraphiqueLargeur-1, $this->GraphiqueHauteur-1, $this->GraphiqueCouleurNoir);
 }
 
 public function Courbe()
 {
 ImagePng($this->GraphiqueImage);
 }
 }
?>
    Fatal error: Class 'Graphique' not found in D:\xxxxxxx\xxxx\xxx\xxxxx\image.php on line 4
    car s'il te mets tout ça c'est comme s'il n'interprétait pas le code de ta classe

    A+JYT

  9. #9
    Membre actif

    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Septembre 2002
    Messages : 472
    Points : 262
    Points
    262
    Par défaut
    Bonjour,

    C'est exactement ça, le code était pollué de quote ce qui empêchait au compilateur d'interpréter le code corectement

    Je ne sais pas d'où elles sortent

    Cest fonctionnel maintenant !

    Merci,
    Mathieu
    Embarcadero RAD Studio XE / Microsoft Windows 7 Édition Intégrale (64 bits)

  10. #10
    Membre actif

    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    472
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Septembre 2002
    Messages : 472
    Points : 262
    Points
    262
    Par défaut
    Bonjour,

    Par contre, j'ai encore un soucis, l'image ne se créé que si je mets tout dans le même fichier ou que j'écris le fichier dans un fichier.

    Il m'affiche ça au lieu de l'image :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    ?PNG  IHDR&#56256;&#56320;?me' PLTE?U&#147;~TIDATx?훱0 ð@(䁞? Dzʿ 8?ꦤix?繞繞繞繞繞繞繞繞繞繞繞繞繞繞繥_?Q ??IEND?B`?
    Le problème peut-il venir de l'include ?

    Merci,
    Mathieu
    Embarcadero RAD Studio XE / Microsoft Windows 7 Édition Intégrale (64 bits)

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Oracle] Problème de connexion avec PHP 5.1.4
    Par Mimo dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 20/09/2006, 17h41
  2. [PHP-JS] Problème de JavaScript avec PHP ?
    Par MaTHieU_ dans le forum Langage
    Réponses: 9
    Dernier message: 03/08/2006, 22h27
  3. [MySQL] Problème d'apostrophe avec PHP
    Par gcooo dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 28/04/2006, 14h08
  4. [LDAP] problème connexion anonyme avec php à Active Directory
    Par anto48_4 dans le forum Bibliothèques et frameworks
    Réponses: 7
    Dernier message: 02/03/2006, 16h50
  5. [PHP-JS] problème de javascript avec php
    Par ph_anrys dans le forum Langage
    Réponses: 9
    Dernier message: 02/03/2006, 10h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo