Re: [PHP] Help: arrays in a class
On Wed, 28 Jan 2004 [EMAIL PROTECTED] wrote: > in php you have to access a member variable (or methods) with: > $this->varname (without the "$") > > e.g.: $this->includedFile = array(); > > hope this helps AHA! I think that's it. The comment someone sent to me (Sorry, i'm awful with names) about $this->$includeFiles=array() maybe corrupting all of $this apparently seemed true. Thanks again all :) Marc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help: arrays in a class
John W. Holmes wrote: You have an extra $ sign in your variables names. $this->fName instead of $this->$fName Not sure if that'll solve all your problems, but it's a start. ---John Holmes... Oh, sure. Point out what I missed in my eval. ;) -- By-Tor.com It's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help: arrays in a class
From: <[EMAIL PROTECTED]> > class clsfTreeNode > { > > //member variables > var $fName; > var $fData; > var $includedFiles; > > //constructor > function clsfTreeNode( $fileName ) > { > $this->$fName = $fileName; > $this->$fData = file_get_contents($this->$fName); > > $this->ParseFile(); You have an extra $ sign in your variables names. $this->fName instead of $this->$fName Not sure if that'll solve all your problems, but it's a start. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help: arrays in a class
[EMAIL PROTECTED] wrote: Here's the problem. In ParseFile I call the function: array_push($this->$includedFiles, $ifName); Here you have it ending in an 's' where $ifName is the name of an include file I found in the code. However, I get an error stating the first argument must be an array. So I tried making the constructor look like this: function clsfTreeNode( $fileName ) { $this->$fName = $fileName; $this->$fData = file_get_contents($this->$fName); $this->$includedFile = array(); Here you have it without an 's' $this->ParseFile(); print count($this->$includedFiles); } and that seems to work ok EXCEPT that $fData also becomes an array and it's contents erased! I've tried moving things around, etc but no matter where i make $includedFile an array $fData gets screwed up. If I don't explicitly make $includedFile an array then nothing works anyway. I'm going out of my mind trying to get this to work, and it shouldn't be so hard. I'm using php 4.3.4 on a WinXP machine. Any thoughts? Don't know if the 's' is the problem, but it's a start. Also, you may want to declare you $includeFile(s) as an array at the start of your class. I'm just guessing here, but declaring it as such ($this->$includeFile = array()) may be emptying $this too. -- By-Tor.com It's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help: arrays in a class
Hi all, I'm having some trouble here and I hope you can help. I'm writing a class for PHP to help track includes in a c++ source file. My class has 3 member variables: a filename file contents array of files that file includes The class definition looks like this class clsfTreeNode { //member variables var $fName; var $fData; var $includedFiles; //constructor function clsfTreeNode( $fileName ) { $this->$fName = $fileName; $this->$fData = file_get_contents($this->$fName); $this->ParseFile(); print count($this->$includedFiles); } function ParseFile(); { ...Long Drawn Out Code Omitted... } }; Here's the problem. In ParseFile I call the function: array_push($this->$includedFiles, $ifName); where $ifName is the name of an include file I found in the code. However, I get an error stating the first argument must be an array. So I tried making the constructor look like this: function clsfTreeNode( $fileName ) { $this->$fName = $fileName; $this->$fData = file_get_contents($this->$fName); $this->$includedFile = array(); $this->ParseFile(); print count($this->$includedFiles); } and that seems to work ok EXCEPT that $fData also becomes an array and it's contents erased! I've tried moving things around, etc but no matter where i make $includedFile an array $fData gets screwed up. If I don't explicitly make $includedFile an array then nothing works anyway. I'm going out of my mind trying to get this to work, and it shouldn't be so hard. I'm using php 4.3.4 on a WinXP machine. Any thoughts? THanks Marc -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php