PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > [PHP5] Assigning values to class member is c-tor
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
[PHP5] Assigning values to class member is c-tor

Réponse
 
LinkBack Outils de la discussion
Vieux 23/02/2008, 21h39   #1
Andrew Falanga
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut [PHP5] Assigning values to class member is c-tor

Hi,

I'm trying to learn how PHP classes work. I'm very familiar with C++
and such, but something that I thought should work is giving me
grief. Basically, this is what I have.

class myclass {
private $somevar;

public __construct($value) {
$this->$somevar = $value;
}
}

Then, in my other code I have:

require("path/to/library.php");

$obj = new $myclass("assign it this");


When I attempt to load this page in my browser, I'm greeted with this
error:

Cannot access empty property in /usr/local/www/data-dist/mch/library/
generic_table.php on line 19

This is coming from the variable assignment in my c-tor in the class
definition. Why isn't this working and how would I make it work?

Andy
  Réponse avec citation
Vieux 23/02/2008, 21h43   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP5] Assigning values to class member is c-tor

Andrew Falanga wrote:
> Hi,
>
> I'm trying to learn how PHP classes work. I'm very familiar with C++
> and such, but something that I thought should work is giving me
> grief. Basically, this is what I have.
>
> class myclass {
> private $somevar;
>
> public __construct($value) {
> $this->$somevar = $value;
> }
> }
>
> Then, in my other code I have:
>
> require("path/to/library.php");
>
> $obj = new $myclass("assign it this");
>
>
> When I attempt to load this page in my browser, I'm greeted with this
> error:
>
> Cannot access empty property in /usr/local/www/data-dist/mch/library/
> generic_table.php on line 19
>
> This is coming from the variable assignment in my c-tor in the class
> definition. Why isn't this working and how would I make it work?
>
> Andy
>


Andy,

Just minor problem - but a common one. It should be

$this->somevar = $value;

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 23/02/2008, 21h47   #3
Andrew Falanga
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Assigning values to class member is c-tor

On Feb 23, 2:43 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Andrew Falanga wrote:
> > Hi,

>
> > I'm trying to learn how PHP classes work. I'm very familiar with C++
> > and such, but something that I thought should work is giving me
> > grief. Basically, this is what I have.

>
> > class myclass {
> > private $somevar;

>
> > public __construct($value) {
> > $this->$somevar = $value;
> > }
> > }

>
> > Then, in my other code I have:

>
> > require("path/to/library.php");

>
> > $obj = new $myclass("assign it this");

>
> > When I attempt to load this page in my browser, I'm greeted with this
> > error:

>
> > Cannot access empty property in /usr/local/www/data-dist/mch/library/
> > generic_table.php on line 19

>
> > This is coming from the variable assignment in my c-tor in the class
> > definition. Why isn't this working and how would I make it work?

>
> > Andy

>
> Andy,
>
> Just minor problem - but a common one. It should be
>
> $this->somevar = $value;
>


WOW! That was minor. Thanks much. I was nearly beginning to pull
out what is left of my hair.

Andy
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 00h27.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10068 seconds with 11 queries