Hi Erik

Thanks for the reply.  I'm not sure how I missed the opening { in my
message -- I copy/pasted the code.  But the opening { is definitely there in
the code -- I'd get a nice error message if it weren't.  I believe it's OK
to have a ; after the class def end-brace, but I removed it and I got the
same symptoms.  I also believe it's OK to not have the () in the "new test"
instance assignment as long as my constructor takes no parameters.  I added
the (), and didn't get different results.

I'm not sure what you mean when you say "Don't you want to....  perform your
error-testing functions on the instances?"  I'm trying to initialize some
class-arrays in the constructor.  I put some echo"" statements in there to
try and figure out what was going on.  The example is just an example -- the
smallest piece of code I could make (presumably) that would exhibit the
symptoms.  The purpose for the "real" class I'm working with is to
encapsulate several arrays (one of which is an array of arrays) along with a
few other variables into a data class that can be put/retrieved as a single
object into the session.  The reason is so that all the code that builds
these arrays only happens when the user hits the first page.  Then the
arrays are available from the session on subsequent hits.

My problem is that when I assign an empty array to a variable, I get
different results depending on whether that variable is in an object or not.
In the case of assigning $a=array(); outside of an object, each element of
the array is empty (as I expected).  But when assigning
$this->$words=array(); results in $this->$words["Amy"] (or any other element
for that matter) already being assigned an array.  And if I look at the
elements of those arrays, they are also initialized to arrays.  I don't know
how deep it goes.

The way I noticed this at first was like this:  In the constructor, I'm
reading phrases from a file and putting each word into the $words array, and
assigning $words[$word]=array($phrasenum);  (so each word in the $words
array gives back an array containing the id's of the phrases it appears in)
When I come across a word that I've already added for phrase 1 in phrase 2,
I expect it to already exist in the array, because I put it there the first
time I came across the word in phrase 1.  Instead, Every element is
pre-assigned to another array, and so the code gets confused, thinking that
it has entries for any word I care to index the array with.

Sorry for the long drawn-out message.  Maybe it will help?



"Erik Price" <[EMAIL PROTECTED]> wrote in message
> I might be completely mistaken here, but it looks like there are a few
> errors in your code:
> - No starting brace for the test() method
> - semi-colon used after class def end-brace
> - no parentheses after "new test" instance assignment
> Don't you want to keep your class as general as possible, and perform
> your error-testing functions on the instances?  It's hard for me to tell
> what kind of data you are trying to represent with this class.  My
> advice is that, even if it seems unnecessarily didactic, you use some
> sort of actual object to help you visualize what you are trying to do
> with this class, like Person() or something -- it helps.  I can't figure
> out what this class is even supposed to do.
> Erik
> Erik Price
> Web Developer Temp
> Media Lab, H.H. Brown

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to