Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Simple OOP question

General discussions related to php

Moderators: macek, egami, gesf

Simple OOP question

Postby freshnet » Fri Sep 07, 2012 6:03 am

I am just starting to code in OOP again after not using it for ages, and I have run up against a blocker. Is there anything special that has to be done to use arrays in PHP classes? For example, let's say I have a function as follows (I've changed the names and values but the idea is the same)

Code: Select all
//I have declared the variables above this, including the one holding the array
public function pitcherRatingCalc()
   {
   $this->pitches = array($this->fastball,$this->curve,$this->slider);
   $this->pitcherRating = array_sum($this->pitches);
   }


This is a very simple function and I'd think by calling

Code: Select all
$pitcher = new pitcher;
$pitcher->curve = 100;
$pitcher->fastball = 100;
$pitcher->pitcherRatingCalc;
echo $pitcher->pitcherRating;


that I would get the sum of the ratings, but instead I get nothing. Can someone tell me what I'm doing wrong please?
User avatar
freshnet
php-forum Active User
php-forum Active User
 
Posts: 277
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Re: Simple OOP question

Postby freshnet » Fri Sep 07, 2012 4:56 pm

I knew it was something simple, I was just missing the (), so I should have had $pitcher->pitcherRatingCalc();. On with the show!
User avatar
freshnet
php-forum Active User
php-forum Active User
 
Posts: 277
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada


Return to PHP General

Who is online

Users browsing this forum: landi and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.