Jump to content

Search the Community

Showing results for tags 'php oop'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 8 results

  1. How would I remove an instance of a class inside a array The content is stored inside an array. and the array inside $_SESSION ['cart'] //My Items class variables are protected. class Item { protected $id; protected $name; .... I will have have Multiple instances of $item inside the array. Cant use unset because its protected $item = new Item($result->id, $result->name); $_SESSION['cart'][] = $item;
  2. Hi, please help. I deliberately made a mistake in my query… can’t get the Exception to display an error message. public function updatename($name = null, $id = null) { if (!$id && $this->isLoggedIn()) { $id = $this->data()->id; } $parms = array(); $parms[] = array(':name', $name, PDO::PARAM_STR); $parms[] = array(':id', $id, PDO::PARAM_INT); if (!$this->_db->query("UPDATE users " . "SET name = :this_variable_not_found" . " WHERE id = :id", $parms)) { throw new Exception('There was a problem updating.'); } } public function query($sql, $data_in = array()) { $this->_error = false; if ($data_in) {// prepared query $this->_query = $this->_pdo->prepare($sql); // this example extends the pdo class foreach ($data_in as $arr) { if (isset($arr[2])) {// type supplied $this->_query->bindValue($arr[0], $arr[1], $arr[2]); } else {// no type supplied $this->_query->bindValue($arr[0], $arr[1]); // defaults to string type } } if ($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else { $this->_error = true; } } else {// non-prepared query $this->_query = $this->_pdo->prepare($sql); if ($this->_query->execute()) { $this->_results = $this->_query->fetchAll(PDO::FETCH_OBJ); $this->_count = $this->_query->rowCount(); } else { $this->_error = true; } }// code to retrieve the result from the query.... return $this; }
  3. i am watching a youtube tutorial for a register and login page the register and login parts work fine but once the user is logged in the logout button will not work it won't delete the session but if i delete the session using the inspect element of my browser and refresh the page the user will be logged out but the button will not work. here is the youtube part I'm up to. would like to continue with these parts once this problem is fixed I've tried a few debugging methods that you will see in my code witch there is a lot of but i think its all worth showing because the functions go across different files. index.php <?php require_once 'core/init.php'; if(Session::exists('home')) { '<p>' . Session::flash('home') . '</p>'; } $user = new User(); if($user->isLoggedIn()) { ?> <p>Hello <a href="#"><?php echo escape($user->data()->username); ?> </a></p> <ul> <li><a href="logout.php">Log out</a></li> </ul> <?php } else { echo '<p>You need to <a href="login.php">Log In</a> or <a href="register.php">Register</a></p>'; }
  4. Hi everyone, I am starting to learn PHP OOP and would like to know if you could help me understanding the scopes a little bit better. I have created the below code during my courses, but cannot work out how to reuse $this->total in another class. I have set the $total; to protected and was wishing to be able to use it in my second class but it returned an error. Any idea how I could use this variable in another class while set with the scope of Protected please? Thank you so much! Class Calculator{ public $number1; public $number2; protected $total; function setNumber1($int){ $this->number1 = (int) $int; } function setNumber2($int){ $this->number2 = (int) $int; } function Calculate(){ $this->total = $this->number1 + $this->number2; } function getResult(){ return $this->total; } } $Calculator = new Calculator(); $Calculator->setNumber1(5); $Calculator->setNumber2(10); $Calculator->Calculate(); echo $Calculator->getResult() . "<br>"; Class secondCalculator extends Calculator { $this->total = $this->number3 + $this->number4; } Ben
  5. Hey guys, got a bit of a complicated question for you... I was challenged to build a Finite State Machine based game by a friend with some rudimentary AI in php. After doing a little research, planned it out to have the following classes in this structure -world --food --nest ---ant Where world would be the highest level class, and contain all the instances of different objects + save/load functionality and such. The problem I'm having is acessing items in the higher level class, without either adding the initial declaration of $world as a global variable or just including a reference in the initial instance of each class item. I have to working, but it's nothing what I'd like. for instance: To access and sort through all the posx/posy coords of the ants presently on screen, I have to go: $this->world->checklocation($this->posx , $this->posy) using a reference I passed to it in the constructor(the world item). Is there a easier way to access information from a higher level object other then passing a reference to it from the original? Right now the only reason that the lower level objects know about the highest one at the moment, is I used the global keyword... and I'd rather know the right way of doing this, rather then the duct-taped way I'm using. (I've included the source code... warning though, it's messy and undocumented)
  6. Hello i have the following error in php using this class. It seems it's because of the new modifications in php >= 5.2, how it handles this. I have no idea how to solve this problem tried with ArrayObject but didn't manage doing anything. I hope someone from here might help me Thank you very much for taking time and reading this post / answering. Notice: Indirect modification of overloaded element of Library\Config\Config has no effect in subdomains/prod/index.php on line 33 use \ArrayObject; use \ArrayAccess; use \Countable; use \IteratorAggregate; use \ArrayIterator; use \Twelve\SingletonPattern\LazySingleton; use \Twelve\SingletonPattern\Interfaces\ILazySingleton; /** * Singleton With Configuration Info */ class Config extends ArrayObject implements ArrayAccess, Countable, IteratorAggregate, ILazySingleton { /** * Instance Var * @var Config */ protected static $_instance = null; /** * Stores FileName * @var Config */ protected static $_configFile = ''; /** * Config Settings Array * @var Config */ protected $_settings = array(); public static function getInstance(){ return LazySingleton::getInstance(__CLASS__); } /** * Set the Config File Path */ public static function setFile($filePath) { static::$_configFile = $filePath; } public function __construct() { LazySingleton::validate(__CLASS__); // Allow accessing properties as either array keys or object properties: parent::__construct($this->_settings, ArrayObject::ARRAY_AS_PROPS); $values = include(static::$_configFile); if(is_array($values)) { $this->_settings = $values; } } /** * Prevent Cloning */ public function __clone() { trigger_error('Clone is not allowed.', E_USER_ERROR); // No Cloning Allowed } /** * Returns the Number of Elements Inside the Config File * @var Config * @return Integer Number of Elements Inside Config */ public function count() { return sizeof($this->_settings); } /** * Check if a Given Key Exists * @var Config * @param mixed $offset Key of Item to Check * @return Boolean True if Key Exists, False Otherwise */ public function offsetExists($offset) { return key_exists($offset, $this->_settings); } /** * Retrieve the Value of a Given Key * @param mixed $offset Key of Item to Fetch * @return mixed Value of the Matched Element */ public function offsetGet($offset) { return $this->_settings[$offset]; } /** * Assign a new Value to a Key * @param mixed $offset Key of the Element to Set * @param mixed $value Value to Assign */ public function offsetSet($offset, $value) { $this->_settings[$offset] = $value; } /** * Remove an Item from the Config * @param mixed $offset Key of the Element to Remove */ public function offsetUnset($offset) { unset($this->_settings[$offset]); } /** * Retrieve an Iterator for Config Values * @return Iterator Iterator of Config Values */ public function getIterator() { return new ArrayIterator($this->_settings); } /** * Enables to Set Values Using the Object Notation i.e $config->myValue = 'Something'; */ public function __set($key, $value) { (array) $this->_settings[$key] = $value; } /** * Enables to Get Values using the Object Notation i.e $config->myValue; */ public function &__get($key) { return $this->_settings[$key]; } public function __isset($key) { return isset($this->_settings[$key]); } }
  7. Hi guys, I am new to php oop, I am trying get an object of sibling method inside a class, seems not working. here is how i do it. class Upload extends Base_controller{ private function sql () { $get = Upload::all(); } public function get_index() { dd($this->sql()->get); } }
  8. Hi all, I hope you can help me out on this one, I am writing a class that uses soap to fetch data from a server but it gives me a 503 error when the server is not reachable, I am trying to catch it but it doesnt seem to be working: here is what I have so far, please note that i havent not put in the rest of the class so assume the rest is all good below the __construct() method as it is when the service is working and the SOAP errors are getting caught fine with this code, but the Service Unavailable i suspect cannot be caught? Is there another way i can approach this to achieve the same goal? class Khaos_model extends CI_Model { public $clientUrl = "https://999.999.999.999/censored.exe/";//obviously changed for forum public $client = false; public $connection = false; public $connectionerror = false; public function __construct() { parent::__construct(); try { $this->client = new SoapClient($this->clientUrl); $this->connection = true; } catch (SoapFault $fault) { $this->connectionerror = "SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})"; } // } Many Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.