NYCPHP Meetup

NYPHP.org

[nycphp-talk] Trouble with Array of Objects

Malcolm, Gary gmalcolm at professionalcredit.com
Tue May 27 17:15:31 EDT 2003


  if( !is_null( $day_row[ 'start' ] ) ) seems to be the most likely
candidate for the problem...

where do you call toString()?

> -----Original Message-----
> From: Chris Snyder [mailto:chris at psydeshow.org]
> Sent: Tuesday, 27 May, 2003 2:11 PM
> To: NYPHP Talk
> Subject: Re: [nycphp-talk] Trouble with Array of Objects
> 
> 
> Scratching head... have you tried $meetings[] = new Meeting ( 
> etc.); ??
> Not that it should matter, of course.
> 
> Also, are you PHP 4.3.1? (And not 4.3.2RC4?)
> 
> 
> Christopher R. Merlo wrote:
> 
> >On 2003-05-27 16:50 -0400, Bhulipongsanon, Pinyo 
> <Pinyo.Bhulipongsanon at usa.xerox.com> wrote:
> >
> >  
> >
> >>for ( $i = 0 ; $i <= 4 ; $i++ ) {
> >>  $myArray[$i] = codeToCreateObject();
> >>}
> >>
> >>I am not sure if this will help?  Can I see your code?
> >>    
> >>
> >
> >I'll give you the highlights, and spare you most of the MySQL stuff.
> >
> >Here's the class def:
> >
> >  class Meeting {
> >
> >  var $day;
> >  var $start;
> >  var $end;
> >  var $dept;
> >  var $course;
> >  var $building;
> >  var $room;
> >
> >  function Meeting( $day, $start, $end,
> >		    $dept, $course, $section,
> >		    $building, $room ) {
> >    $this->day = $day;
> >    $this->start = $start;
> >    $this->end = $end;
> >    $this->dept = $dept;
> >    $this->course = $course;
> >    $this->building = $building;
> >    $this->room = $room;
> >    print "<p>" . $this->toString( ) . "</p>\
";
> >  }
> >
> >  function toString( ) {
> >    return date( "g:i a", strtotime( $this->start ) ) . " to "
> >      . date( "g:i a", strtotime( $this->end ) ) . ": $this->dept "
> >      . "$this->course $this->section in $this->building 
> $this->room";
> >  }
> >} // class Meeting
> >
> >And here's the relevant code:
> >
> >$meetings = array( );
> >
> >// some more stuff
> >
> >  foreach( $day_names as $day=>$name ) {
> >
> >    $day_query = "select * from meetings where id = 
> \\"{$sec_row[ "$day" ]}\\"";
> >    $day_result = @mysql_query( $day_query );
> >
> >    $day_row = @mysql_fetch_assoc( $day_result );
> >    if( !is_null( $day_row[ 'start' ] ) ) {
> >
> >      $meetings[ $meeting_count ] =
> >        new Meeting( $name, $day_row[ 'start' ], $day_row[ 'end' ],
> >                       $course_row[ 'dept' ], $course_row[ 
> 'course' ],
> >                       $sec_row[ 'section' ], $day_row[ 'building' ],
> >                       $day_row[ 'room' ] );
> >      $meeting_count++;
> >    }
> >  }
> >}
> >
> >Here's what I get on the page.  First, the results of the constructor
> >being called five times:
> >
> >8:00 am to 10:50 am: CMP 103 in B 113
> >
> >8:00 am to 10:50 am: CMP 103 in B 119
> >
> >8:00 am to 10:50 am: CMP 103 in B 113
> >
> >8:00 am to 10:50 am: CMP 103 in B 119
> >
> >8:00 am to 10:50 am: CMP 218 in B 113
> >
> >And then the result of print_r( $meetings ):
> >
> >Array ( [4] => meeting Object ( [day] => Friday [start] => 08:00:00
> >[end] => 10:50:00 [dept] => CMP [course] => 218 [building] 
> => B [room]
> >=> 113 ) ) 
> >
> >And I'm at a loss.
> >  
> >
> 
> 
> 
> --- Unsubscribe at http://nyphp.org/list/ ---
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20030527/fdfbf45b/attachment.html>


More information about the talk mailing list