Not an extended function of an extended PHP class?

In class A, I have this:

protected function createTempTable()
{
    $qry = '
        CREATE TABLE  `'.$this->temp_table.'` (
         `style` VARCHAR( 255 ) NOT NULL ,
         `description` VARCHAR( 255 ) NOT NULL ,
         `metal` VARCHAR( 255 ) NOT NULL ,
         `available` VARCHAR( 255 ) NOT NULL ,
         `center_stone` VARCHAR( 255 ) NOT NULL ,
         `total_weight` VARCHAR( 255 ) NOT NULL ,
         `price` DECIMAL( 10, 2 ) NOT NULL ,
        PRIMARY KEY (  `style` )
        ) ENGINE = MYISAM ;
    ';

    $pdo = PDOManager::getConnection();

    $sth = $pdo->query($qry);
}

Class B extends class A and has the following:

protected function createTempTable()
{
    $qry = '
        CREATE TABLE  `'.$this->temp_table.'` (
         `style` VARCHAR( 255 ) NOT NULL ,
         `syn10` DECIMAL( 10, 2 ) NOT NULL ,
         `gen10` DECIMAL( 10, 2 ) NOT NULL ,
         `syn14` DECIMAL( 10, 2 ) NOT NULL ,
         `gen14` DECIMAL( 10, 2 ) NOT NULL ,
        PRIMARY KEY (  `style` )
        ) ENGINE = MYISAM ;
    ';

    $pdo = PDOManager::getConnection();

    $sth = $pdo->query($qry);
}

ClassB does not actually call createTempTable, it allows it to call the class class ClassA.

So, theoretically, when I create a new class ClassB, it calls the superclass createTempTable(), which should use the version of the ClassB override function. However, this is not the case; it still uses the ClassA version. I confirmed this by running SHOW CREATE TABLEinside ClassB. I expected to have a column syn10, instead I had a column description.

Why is this?

change

Here is the code from class A that calls the function createTempTable:

public function processPriceSheet ($file, $test = false)
{
    if(!file_exists($file))
    {
        die('The file "'.$file.'" does not exist.');    
    }
    $fp = fopen($file,'r');

    $this->createTempTable();

    while (!feof($fp)) 
    {   
        $row = fgetcsv($fp);
        $this->processLine($row);
    }
    fclose($fp);

    $products_updates = $this->massUpdate();

    $this->findMissingFromDB();
    $this->findMissingFromCSV();

    return $products_updates;
}

Here's how ClassA starts:

class AdvancedCsvFeed
{

    protected $vendor_prefix;
    protected $style_column;
    protected $price_column;
    protected $price_multiplier;
    protected $instock_column;

    protected $temp_table = 'csv_tmp';

    public function __construct($price_column, $style_column, $vendor_prefix = '', $price_multiplier = 1, $instock_column = 0)
    {
        $this->vendor_prefix = $vendor_prefix;
        $this->price_column = $price_column;
        $this->style_column = $style_column;
        $this->price_multiplier = $price_multiplier;
        $this->instock_column = $instock_column;
    }

... other functions

So begins ClassB:

class MothersRingsAdvancedCsvFeed extends AdvancedCsvFeed
{
    private $syn10_price_column;
    private $gen10_price_column;
    private $syn14_price_column;
    private $gen14_price_column;

    public function __construct($syn10_price_column, $gen10_price_column, $syn14_price_column, $gen14_price_column, $style_column, $price_multiplier = 3)
    {
        $this->syn10_price_column = $syn10_price_column;
        $this->gen10_price_column = $gen10_price_column;
        $this->syn14_price_column = $syn14_price_column;
        $this->gen14_price_column = $gen14_price_column;
        $this->style_column = $style_column;
        $this->price_multiplier = $price_multiplier;
    }

... other functions

And this is how class B is initiated:

$s = new MothersRingsAdvancedCsvFeed(2,3,4,5,1);
echo $s->processPriceSheet('mothers_rings.csv');
+5
1

EDIT: , $temp_table. : , - AdvancedCsvFeed MySQL csv_tmp, $s->processPriceSheet , ? MothersRingsAdvancedCsvFeed set

$this->temp_table = 'mothers_rings_csv_tmp';

ORIGINAL:

- . :

<?php

class TestOne {
  public function foo() {
    echo "TestOne foo.";
  }
  public function bar() {
    $this->foo();
    echo " TestOne bar.";
  }
}
class testTwo extends TestOne {
  public function foo() {
    echo "TestTwo foo.";
  }
}

$one = new TestOne();
$two = new TestTwo();

$one->foo();
$two->foo();

$one->bar();
$two->bar();

, :

TestOne foo.TestTwo foo.TestOne foo. TestOne bar.TestTwo foo. TestOne.

, - , . , , createTempTable()?

+4

All Articles