br0ken
Members-
Posts
421 -
Joined
-
Last visited
Never
Contact Methods
-
Website URL
http://fishpig.co.uk
Profile Information
-
Gender
Male
br0ken's Achievements
Member (2/5)
0
Reputation
-
Stop fatal error on abstract class instantiation
br0ken replied to br0ken's topic in PHP Coding Help
Please ignore my question! Although I've been Googling this subject for a while, I didn't stumble across what I was looking for until just after I posted. If any one wants to know how to figure out whether or not a class is abstract at run time see the following link: http://php.net/manual/en/class.reflectionclass.php -
When I try to instantiate an abstract class a fatal error occurs. Is it possible to somehow suppress this error and return it as a string so that execution can continue? If this isn't possible, is there a way to test whether or not a certain class is abstract before trying to instantiate it? Thanks in advance!
-
This isn't really a Wordpress forum but have you read this page: http://codex.wordpress.org/Template_Tags/get_posts That tells you everything you need to know and more
-
Arg!!! I am going crazy with header function !!
br0ken replied to jtorral's topic in PHP Coding Help
You need a semi colon after Location. <?php header("Location: http://www.google.com"); exit; // Also, always add an exit after your header ?> -
Ignace is correct that a Student and Teacher are separate entities and therefore both need a separate class, but you are also right in noticing they share a common factor; they are both a human! The best way to do this would be to have a base class Human (or Person) and have both Teacher and Student extend from them. <?php abstract class Human { protected $_name = ''; protected $_gender = ''; protected $_role = ''; public function getName() { return $this->_name; } } class Teacher extends Human { public function __construct($name) { $this->_name = $name; $this->_role = 'Teacher'; } } class Student extends Human { public function __construct($name) { $this->_name = $name; $this->_role = 'Student'; } } $teacher = new Teacher('Mrs Smith'); $student = new Student('Jack Adams'); echo $teacher->getName(); //Returns Mrs Smith echo $student->getName(); // Returns Jack Adams ?> The benefit of this method is that both Teacher and Student can use the Human functions. This will save you duplicating code between the two objects.
-
writing a function based on if it is the index file or not?
br0ken replied to kade119's topic in PHP Coding Help
Actually you won't have to add the folder into the array as the $_SERVER['REQUEST_URI'] has the basename function wrapped around it. This function takes a filename and path as a string and returns the filename portion. This means that any folder on it will be removed and therefore you won't have to check it. To test your script, try printing out the value of basename($_SERVER['REQUEST_URI']) and see what you get on different pages. You can add which ever values are displayed on the homepage to the array. -
Based on the question, I imagine Zend is too complex for what this user requires. Also, with no knowledge of Zend I imagine the code sample you posted makes no sense what so ever.
-
I defined my array manually but you could parse yours dynamically easily enough. You could write this functionality manually using either substr and strpos or regular expressions. Alternatively, you could use one of the many pre-written PHP CSS parsers. http://www.google.co.uk/search?q=php+css+parser&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
-
There are various different methods to creating your 'environment' (for the lack of a better word). The method you have described will work fine, however you will need to watch out for naming collisions. By asking whether your method is good practise, as opposed to just coding and hoping shows that you are on the right track. Keep asking questions and you'll be fine!
-
Prevent Spoofed Contact Form Submission_Security of Web form
br0ken replied to dingi's topic in PHP Coding Help
You could install a capctha box. They're one of those crazy things that force a user to write some scrambled words before allowing them to post. You can get some free ones and they're easy enough to install. http://www.captcha.net/ (There's load more, just Google Free Captcha) -
how you make a mysql query to be exactly accurate
br0ken replied to dbradbury's topic in PHP Coding Help
the equality operator (equals sign) checks for an exact match. If you have space on the end or the case is different then a match will not be returned. To get inexact matches you could convert the text to lower case using LOWER or use the LIKE operator. -
If I was doing something like that, I would parse the CSS into an array. Each element in the array would have the selector as the key and the values as the value. For example: <?php $css = array('body' => 'font-family:Arial;font-size:12px;', 'a' => 'color:#000;', 'a.big' => 'font-size:18px; font-weight:bold;', ); $selectorToFind = 'a.big'; $css[$selectorToFind] = str_replace('font-size:18px;', 'font-size:30px;', $css[$selectorToFind]); ?>
-
is this logical? '$l = ($_GET($row['forum_id']));'
br0ken replied to dbradbury's topic in PHP Coding Help
That is a little confusing! I won't pretend to know what you're trying to achieve but I did notice that you're trying to use the $album variable in your query, but you haven't actually initialised it yet. Where you have: if(isset($_GET['album'])) { Change it to if($album = isset($_GET['album'])) { -
writing a function based on if it is the index file or not?
br0ken replied to kade119's topic in PHP Coding Help
<?php // You should probably move this into your functions file function is_homepage() { return in_array(basename($_SERVER['REQUEST_URI']), array('', 'index.php', 'index.html', '/')); } $flash = 'http://www.testsite.com/banner.swf'; if (is_homepage()) { ?> <object width="550" height="400"> <param name="movie" value="<?php echo $flash ?>"> <embed src="<?php echo $flash ?>" width="550" height="400"> </embed> </object> <?php } else { echo '<img src="banner.jpg" alt="Image Banner"/>'; } ?> -
I just Google 'PHP Simple Calendar' and got quite a lot of results. This one looks pretty simply: http://php.about.com/od/finishedphp1/ss/php_calendar.htm