Search Results

Search found 3120 results on 125 pages for 'php5 oop'.

Page 9/125 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Some instruction needed for PHP OOPS concepts.

    - by Avinash
    Hi, I need to clear some OOPS concepts in PHP. 1) Which is faster $this-method(); or self:method(); 2) I know the concept of static keyword but can you please post the actual Use of it. Since it can not be accessed by the instance, but is there ant benefit for that? 3) what is factory? How can i use it? 4) What is singleton? How can i use that? 5) What is late static binding? http://www.php.net/manual/en/oop5.intro.php I have gone through below link but I am not getting clear with it. Thanks Avinash

    Read the article

  • PHP: Recursive array function

    - by Industrial
    Hi everybody, I want to create a function that returns the full path from a set node, back to the root value. I tried to make a recursive function, but ran out of luck totally. What would be an appropriate way to do this? I assume that a recursive function is the only way? Here's the array: Array ( [0] => Array ( [id] => 1 [name] => Root category [_parent] => ) [1] => Array ( [id] => 2 [name] => Category 2 [_parent] => 1 ) [2] => Array ( [id] => 3 [name] => Category 3 [_parent] => 1 ) [3] => Array ( [id] => 4 [name] => Category 4 [_parent] => 3 ) ) The result I want my function to output when getting full path of node id#4: Array ( [0] => Array ( [id] => 1 [name] => Root category [_parent] => ) [1] => Array ( [id] => 3 [name] => Category 3 [_parent] => 1 ) [2] => Array ( [id] => 4 [name] => Category 4 [_parent] => 3 ) ) The notoriously bad example of my recursive skills: function recursive ($id, $array) { $innerarray = array(); foreach ($array as $k => $v) { if ($v['id'] === $id) { if ($v['_parent'] !== '') { $innerarray[] = $v; recursive($v['id'], $array); } } } return $innerarray; } Thanks!

    Read the article

  • Regular Expressions: RegEx for determining valid PHP class property names?

    - by Brian Lacy
    I am using PHP's magic __set and __get methods to access a private array in a class. I want to make sure the property names requested (i.e. $myObj->FakeProperty) are valid according to PHP property name rules before accessing them. My current RegEx isn't doing the trick; with my test values, _12 always falls through the cracks. I'm not actually sure that my test values even represent a realistic representation of what is and isn't allowed for PHP class property names, but I'm not really too concerned about it, just that I have some sort of rudimentary check in place. Test Fields: albert12 12Albert _12 _Albert12 _12Albert _____a_1 RegEx: ^(?=_*[A-z]+)[A-z0-9_]+$

    Read the article

  • Is there a simple way to emulate friendship in php 5.3

    - by Itay Moav
    I need some classes to befriend other classes in my system. Lack of this feature made me publicize some methods which shouldn't be public. The consequences of that are that members of my team implement code in a bad and ugly way which causes a mess. Is there a way to define a friendship in php 5.3? (I am aware of http://bugs.php.net/bug.php?id=34044 You might want to vote there if there is no simple solution).

    Read the article

  • How to return Current Object in a Static function in PHP

    - by streetparade
    I neet access to current object in a static method. Code: protected static $name; public static function name($modulename) { self::$name = $modulename; } public function __call($name, $arguments) { $me = new test(self::$name); return $me->$name($arguments); } I want to be able to call method log in Log class. Like this echo Mods::name("Log")->log("test"); How do i do that?

    Read the article

  • Why is there a constructor method if you can assign the values to variables?

    - by Joel
    I'm just learning PHP, and I'm confused about what the purpose of the __construct() method? If I can do this: class Bear { // define properties public $name = 'Bill'; public $weight = 200; // define methods public function eat($units) { echo $this->name." is eating ".$units." units of food... <br />"; $this->weight += $units; } } Then why do it with a constructor instead? : class Bear { // define properties public $name; public $weight; public function __construct(){ $this->name = 'Bill'; $this->weight = 200; } // define methods public function eat($units) { echo $this->name." is eating ".$units." units of food... <br />"; $this->weight += $units; } }

    Read the article

  • PHP - Concatenating objects and casting to string - bad idea?

    - by franko75
    Is it bad practice to concatenate objects when used in this context: $this->template->head .= new View('custom_javascript') This is the way i normally add extra css/js stuff to specific pages. I use an MVC structure where my basic html template has a $head variable which I set in my main Website_controller. I have used this approach for a while as it means I can just add bits and pieces of css/js stuff from whichever page/controller needs it. But having come across a problem in PHP 5.1.6 where the above code results in "Object ID #24", the result of toString() not being called i think, I am rethinking whether i should just fix this to work in PHP 5.1.6 or if i should rethink this approach in general. Any pointers appreciated!

    Read the article

  • Is there any way to achieve multiple inheritance in php?

    - by Starx
    Lets say I have a parent class class parent { } ..... This parent has three sub class class child1 { } class child2 { } class child3 { } and these child classes have further smaller parts like class child1subpar1 { } class child1subpar2 { public function foo() { echo "hi"; } } class child2subpar1 { } class child2subpar2 { } Now, how to sum this whole up like class child1 extends child1subpar1, child1subpar2 { } class child2 extends child2subpar1, childsubpar1 { } class parent extends child1,child2,child3 { } I need to execute the methods in its inherited classes and do something like this $objparent = new parent; $objparent - foo();

    Read the article

  • PHP Session Class and $_SESSION Array

    - by Gianluca Bargelli
    Hello, i've implemented this custom PHP Session Class for storing sessions into a MySQL database: class Session { private $_session; public $maxTime; private $database; public function __construct(mysqli $database) { $this->database=$database; $this->maxTime['access'] = time(); $this->maxTime['gc'] = get_cfg_var('session.gc_maxlifetime'); session_set_save_handler(array($this,'_open'), array($this,'_close'), array($this,'_read'), array($this,'_write'), array($this,'_destroy'), array($this,'_clean') ); register_shutdown_function('session_write_close'); session_start();//SESSION START } public function _open() { return true; } public function _close() { $this->_clean($this->maxTime['gc']); } public function _read($id) { $getData= $this->database->prepare("SELECT data FROM Sessions AS Session WHERE Session.id = ?"); $getData->bind_param('s',$id); $getData->execute(); $allData= $getData->fetch(); $totalData = count($allData); $hasData=(bool) $totalData >=1; return $hasData ? $allData['data'] : ''; } public function _write($id, $data) { $getData = $this->database->prepare("REPLACE INTO Sessions VALUES (?, ?, ?)"); $getData->bind_param('sss', $id, $this->maxTime['access'], $data); return $getData->execute(); } public function _destroy($id) { $getData=$this->database->prepare("DELETE FROM Sessions WHERE id = ?"); $getData->bind_param('S', $id); return $getData->execute(); } public function _clean($max) { $old=($this->maxTime['access'] - $max); $getData = $this->database->prepare("DELETE FROM Sessions WHERE access < ?"); $getData->bind_param('s', $old); return $getData->execute(); } } It works well but i don't really know how to properly access the $_SESSION array: For example: $db=new DBClass();//This is a custom database class $session=new Session($db->getConnection()); if (isset($_SESSION['user'])) { echo($_SESSION['user']);//THIS IS NEVER EXECUTED! } else { $_SESSION['user']="test"; Echo("Session created!"); } At every page refresh it seems that $_SESSION['user'] is somehow "resetted", what methods can i apply to prevent such behaviour?

    Read the article

  • Calling overridden method from within overriding method in OO PHP

    - by paddymcc
    Working in a symfony model, I want to override a function and call the overridden function from within the overriding one, along the lines of class MyClass extends BaseMyClass { function setMyProperty($p) { parent::setMyProperty($p); //do some other stuff } } This is resulting in a segmentation fault. I don't want to alter the parent class - it's been generated by symfony, and may feasibly be overwritten in the future if the model is rebuilt. This seems like something that should be straightforward, but I'm struggling to find the solution. Thanks for any advice

    Read the article

  • PHP: Prevent chained method from returning?

    - by Industrial
    Hi, I am having some headaches regarding method chaining for a quite simple PHP class that returns a value, which sometimes need to go through a decryption process: $dataset = new Datacontainer; $key = $dataset->get('key'); $key2 = $dataset->get('key')->decrypt(); The get method is where the return lives. So the call to the decrypt method on the second row isn't going to work in its current state. Can I do something to setup the get method to return only when nothing is chained to it, or what would be the best way to re-factor this code?

    Read the article

  • PHP Type Hinting: array supported, object NOT?

    - by Marius Burz
    Am I missing something or there really is no support for generic object type hinting in PHP 5.x? I find it really strange that hinting arrays is supported while hinting objects is not, at least not out of the box. I'd like to have something like this: function foo(object $o) Just as we have: function foo(array $o) Example of possible use: methods of an objects collection class. Workaround: using an interface "Object" implemented by all classes or extending all classes from a generic class "Object" and writing something like this: function foo(Object $o) Well, that just ain't cute. Edit: somebody suggested in a deleted post using stdClass. It doesn't work: Catchable fatal error: Argument 1 passed to c::add() must be an instance of stdClass, instance of b given

    Read the article

  • Define a class dynamically?

    - by Pekka
    Is there a way to dynamically and conditionally create a class definition in PHP, i.e. if (condition matches) include file containing class definition else class myclass extends ancestor_class { .................... } without eval()? My background is the accepted answer to this question. I am looking for the best way to build a untouchable core library, with user-defined empty classes extending the core library if necessary. I want to create the final class definition "on the fly" if there is no user-defined empty class for a certain ancestor class.

    Read the article

  • which situation abstract class i should use

    - by Bharanikumar
    Hi , Am not worked on extream level of oops in my projects , So i have little doubts , In which situation should i use abstract method or classes , Basically i know about abstract class definition and flow, I got details from this URL Doubt is which situation should i use abstract class and methods ,

    Read the article

  • php require class call from inside method

    - by jera
    from my understanding, require pastes code into the calling php file. what if you were requiring from inside a method...it would paste the entire code/class inside the method, blocking the next statement in the method. eg. function test() { require 'pathtosomeclasscode'; somestatement; // any code after the require is blocked. } how do i get around this, to be able to require code where-ever, without it being pasted in that exact spot? Thanks in advance for your help.

    Read the article

  • Why does PHP 5.2 disallow abstract static class methods?

    - by Artem Russakovskii
    After enabling strict warnings in PHP 5.2, I saw a load of strict standards warnings from a project that was originally written without strict warnings: Strict Standards: Static function Program::getSelectSQL() should not be abstract in Program.class.inc The function in question belongs to an abstract parent class Program and is declared abstract static because it should be implemented in its child classes, such as TVProgram. I did find references to this change here: Dropped abstract static class functions. Due to an oversight, PHP 5.0.x and 5.1.x allowed abstract static functions in classes. As of PHP 5.2.x, only interfaces can have them. My question is: can someone explain in a clear way why there shouldn't be an abstract static function in PHP?

    Read the article

  • mysqli insert into database

    - by Simon
    Hello all i have this script and i will not insert into the database and i get no errors :S, do you know what it is? function createUser($username, $password) { $mysql = connect(); if($stmt = $mysql->prepare('INSERT INTO users (username, password, alder, hood, fornavn, efternavn, city, ip, level, email) VALUES (?,?,?,?,?,?,?,?,?,?)')) { $stmt->bind_param('ssssssssss',$username,$password, $alder, $hood, $fornavn, $efternavn, $city, $ip, $level, $email); $stmt->execute(); $stmt->close(); } else { echo 'error: ' . $mysql->error; }

    Read the article

  • Using PHP interfaces in Codeigniter

    - by John Stewart
    I am trying to find out how can I used PHP interfaces in my MVC design. I want to make sure that the design enforces an interface so that any new module would follow that. For example: <?php interface BaseAPI { public function postMessage($msg); } class ServiceAPI implements BaseAPI { public function postMessage($msg) { return $msg; } } class Service_Two_API implements BaseAPI { public function postMessage($msg) { return "can't do this: ".$msg; } } ?> I want to do this in CI. Is it possible? how should I design it?

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >