954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Abstracting the update method. how can i iterate though the array???

Hello..
i have this problem.. im doing some kind of late static binding. im really a new to this and don't know how to solve this problem. please help me to solve it...
What i want to do is instead of using static:: $arr[0].",".static:: $arr[1] i want to iterate though the array.. i tried using a foreach loop but it doesn't work.. i don't understand why.. i will really appreciate if someone demonstrate a code to do this in a better way.
this is my code.

<?php
class MainModel {

public static function create($custArray){
global $connection;

$query="INSERT INTO ".static:: $tblname."(";
$query.=static:: $arr[0].",".static:: $arr[1];
$query.=") VALUES ('".$custArray['name']."','".$custArray['details']."')";

if(mysql_query($query)>0)
{
return true;
}
else
{
return false;
}

}
class ChildModel extends MainModel{

protected static $tblname = 'test';
protected static $arr=array('name','details');

}

//here im calling the method.. just for testing..
if(ChildModel::create(array('name'=>'d','details'=>'s')))

{
echo("its working! ");
}
else
{
echo("its not working! ".mysql_error());
}
?>

Virangya
Junior Poster
122 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 


i had to use a space in between ":: $" so it will display correctly.

Virangya
Junior Poster
122 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

what the heck is this static:: stuff? never heard of it. i would help but i dont know what ur meaning

SKANK!!!!!
Posting Pro in Training
429 posts since Apr 2009
Reputation Points: 15
Solved Threads: 7
 

its used instead of self:: for static binding. you can check this link for more information.
http://php.net/manual/en/language.oop5.late-static-bindings.php

Virangya
Junior Poster
122 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

Design patterns of the classes, methods, variables are always dependent upon the rules of concepts like abstract, static. If we do follow the rule of the abstract class and if we do follow the rule of the static keywords, all design patterns should work fine.

sourcebits
Junior Poster
102 posts since Dec 2008
Reputation Points: 16
Solved Threads: 14
 

To my knowledge, static variables are not inherited. They are only available to that class.

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: