PHP - Difficult Time Understanding Namespaces.
I'm not entirely sure what is wrong with me, but I'm having a super difficult time understanding namespaces.
I have 2 primary classes
# Resides within class.DataTypeBase.php namespace DTB\Base; class DataTypeBase { protected $name = ''; protected function getName() { return $this->name; } protected function setName($name) { $this->name = $name; } } # Resides within class.DataType.php namespace DTB; class DataType extends DataTypeBase { public function process_data(){ .... } }I then have a third file that contains approximately 9 different classes that further extend DataType # Resides within class.DataTypes.php namespace DataTypes; class Silver extends DataType { public function differ($type) { .... } }The namespace system seems to work for class DataTypes, but with the class Silver I get an error message saying that the class DataType does not exist. From what I read online, and using the example above I figured the "extends DataType" may have to be "extends \DTB\DataType" but it results in the same error message. I'm not entirely sure what I need to do for this to work properly Similar TutorialsHey Guys. I am new to using namespaces. I am trying to use it on the code below but it keeps giving me an error message saying Class 'lesson_one\Lecture' not found
I am not sure what I am doing wrong here... I have provided an example below. I know there is a duplicate conditional statement. But I am just working with this code to test out the namespace.
Any help would be really appreciated!
namespace lesson_one; abstract class Lesson { protected $duration; const FIXED = 1; const TIMED = 2; private $costtype; function __construct($duration, $costtype=1) { $this->duration = $duration; $this->costtype = $costtype; } function cost(){ switch($this->costtype) { case self::TIMED: return (5* $this->duration); break; case self::FIXED: return 30; break; default: $this->costtype = self::FIXED; return 30; } } function chargeType() { switch($this->costtype) { case SELF::TIMED: return "hourly rate"; break; case self::FIXED : return "fixed rate"; break; default: $this->costtype = self::FIXED; return "fixed rate"; } } } class Lecture extends Lesson { } class Seminar extends Lesson { } //echo Lesson::FIXED; $lecture = new \lesson_one\Lecture("5", Lesson1::FIXED); echo $lecture->cost(). "<br>"; echo $lecture->chargeType(). "<br>"; when trying to call
get_class($this)it will return the namespace of my class Application\Models\User_Model But what im really after is just User_Model... is there a way of actually getting the class name and not the namespace itself? thought i'd ask before making a class for that...thank you Does the concept of a "Namespace" exist in PHP? If so, how do you use them? This is a snippet from ASP.NET that made me ask this question... Quote <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.SqlClient" %> TomTees
I have to be doing something wrong here, but so far Googling hasn't helped. Take a look he
https://demo.envrin.com/api/classes/apex.app.msg.emailer.html#method_send
The doc-block is correct, or at least as far as I can tell it is, character-by-character. I'm blind though, but have tried different combinations of things like "String" instead of "string" or "@Param" instead of "@param". Made sure the ends of the @param lines ende din a period, and that seemed to help a little.
Nonetheless, why does it keep adding the namespace to everything in front of "string" like that? Any why are the paramaters section all screwed up?
Any help would be appreciated. Thanks!
Hi,
Well, I'm having this
The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'GetSomething'. End element 'Body' from namespace 'http://schemas.xmlso.../soap/envelope/' expected. Found element 'param1' from namespace ''.
The soapclient request itself is something with multiple namespaces, like :
<aaa xmlns="namespace1"> <bbb xmlns="namespace2" xmlns:i="http://www.w3.org/20...hema-instance"> <requestparams>xxxxx</requestparams> </bbb> </aaa> So far I think this may got to do with multiple namespaces, so I've been trying to figure out how to deal with this for hours to no avail. Anyone can shed a light into this problem ? Thanks in advance, so im on chapter 4 of basic java and the teacher said his program implements a simple "decoder ring".
It will prompt the user for a message to decode and decode the message This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330779.0 I notice plenty of CakePHP plugins don't have composer.json files in their github repositories (I'm not sure where composer downloads from if you don't specify a repository, is it github?) so I can't automatically download and update them. For composer to recognise and download the plugins, all thats needed is the composer.js file itself isn't it? Why wouldn't plugin authors just spend an extra 10 minutes and make a composer.js file? I'm guessing theres something I'm missing here, it must not be that simple. I only started using composer so I don't really know what its about yet.
Hi There! I am quite far with this script I'm creating, but there is one thing I am not getting straight. The script shows and hides information from a database by changing checkboxes. This can be filtered by a form. Now my final problem: the checkboxes should start CHECKED instead of unchecked as they start now. It could be done by giving the $film or the $a attribute a start value I guess, but I don't know how. I tried to put $a = "checked=\"checked\""; $film_query = "film='1'"; on several places in the beginning of the script, but it doesn't seem to affect anything. It only works if I put it right before the form, but then it checks the checkboxes every time after the form has been submitted (making it impossible to uncheck it). Not good Could you give me a little help maybe? Thanks a LOT! PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel I'm attempting to convert a huge project I made with mysql to PDO. I have many cases where I would use a WHILE statement to return a query array. Code: [Select] while($row= mysql_fetch_array($result)){From what I've seen so far, it looks as though I need to use a foreach statement to do the same task. Code: [Select] foreach ($dbh->query($sql) as $row){ Is that correct? Hi, can someone help me figure out why the logo div isn't centering? Code: [Select] <?php require_once("functions.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> td { border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #30C; border-right-color: #30C; border-bottom-color: #30C; border-left-color: #30C; } </style> <link href="doggyTreats.css" rel="stylesheet" type="text/css" /> </head> <body> <?php [color=yellow]logo();[/color] navBar(); echo "<div id=\"mainContent\">"; echo "<form action=\"\" method=\"post\" name=\"catalog\">"; DatabaseConnection(); $query = "SELECT * FROM treats"; $result_set = mysql_query($query) or die(mysql_error()); $i = 0; echo "<table>"; while ($row = mysql_fetch_array($result_set)) { echo"<tr><td width=\"2s00px\"><img src=\"{$row['product_pic']}\" /></td><td width=\"200px\">{$row['product_title']}.<br /><br />{$row['product_Description']}.<br /> Price: \${$row['price']}.<br /><br />Quantity <input name=\"quantity\" type=\"text\" size=\"2\" /></td></tr>"; } echo "<tr>"; echo "<td><input name=\"submit\" type=\"button\" value=\"Proceed to Checkout\" />"; echo "</table>"; echo "</form>"; echo "</div>"; footer(); ?> </body> </html> Code: [Select] #navBar { background-color: #060; width: 200px; padding-top: 50px; padding-bottom: 250px; float: left; } #navBar #menu { margin-right: 6px; } .menuOption { background-image: url(assets/bone2a.gif); background-repeat: no-repeat; padding-bottom: 25px; list-style-type: none; height: 20px; padding-top: 26px; text-align: center; } body { background-color: #0089cc; }[color=yellow] #logo { text-align: center; margin-top: 5px; height: 123px; width: 182px; }[/color] #footer { font-style: italic; text-align: center; } .shoppingCart tr th { padding: 5px; } .shoppingCart tr td { padding: 5px; } #mainContent { width: 350px; margin-top: 30px; } Code: [Select] <?php [color=yellow]function logo() { echo "<div id=\"logo\">"; echo "<img src=\"assets/logo.gif\" alt=\"logo\" />"; echo "</div>"; }[/color] function footer() { echo "<div id = \"footer\">"; echo "Auntie Vic\'s Treatery <br />"; echo "PO Box 34092 <br />"; echo "Clermont, IN 46234 <br />"; echo "317-701-0343 <br />"; echo "<a href=\"mailto:auntievics@gmail.com\">Email Us</a>"; echo "</div>"; } function navBar() { echo "<div id = \"navBar\">"; echo "<ul id=\"menu\">"; echo "<li class=\"menuOption\"><a href=\"index.html\">Home</a></li>"; echo "<li class=\"menuOption\"><a href=\"aboutUs.html\">Management Team </a></li>"; echo "<li class=\"menuOption\"><a href=\"treats.html\">Treats </a></li>"; echo "<li class=\"menuOption\"><a href=\"charities.html\">Supported Charities</a></li>"; echo "<li class=\"menuOption\"><a href=\"order.html\">Orders</a></li>"; echo "</ul>"; echo "</div>"; } ?> I have a system that I want to change. Hello, After a user gets input into my Users table in my database, I'm using lastInsertId() to grab the newly created ID and then enter the newly created ID (along with some other stuff) into a separate table. Could this potentially be a problem? In other words, what happens if 2 users on 2 different computers both sign up a the same time? How will be database know which lastInsertId() to use? Here's my current code: $dbWrite->insert('users', $data); $last_id = $dbWrite -> lastInsertId(); // get the ID that was just created $data = array ('course_id' => $_POST['course_id'], 'user_id' => $last_id); $dbWrite->insert('course_enrollment', $data); // Use that new ID in a different table Perhaps there's a way to combine the steps? Thank you for your thoughts... can you guys help with this a little bit? i've been in so many companies. I get so sick of this. people throw terms around all the time and a lot of times, at least what I've noticed, is that a lot of people don't even really know what they're talking about. take for instance, this: https://www.php.net/manual/en/class.iterator.php if you consider the link, it is calling the iterator a class. but, in the article it is described as an interface. to me, that's just ridiculous. you see, what's going to happen with that, is that I'm going to go into a meeting next week and some person from india is going to argue with me about ""well, no, a class is not an interface.....yada yada..."", and on and on and on. obviously this is extremely simple, and most CEOs understand that. I've never understood why engineers do not. it's nothing more than a hierarchy. everything is. sooooo.....to start here, does anyone reading this understand what I'm trying to say? This is nothing more than information management, as everything is anyway. That's why it's very simple. at this point, I would think that no one should have to write code anymore, even if the concepts of low code and no code did not exist. code is so patternized anyway, and there are only so many objects on Earth to mimic in the electronic world, is that not why frameworks were created in the first place? let us start there. comments anyone? thanks. Adam Let's see.... You add values to variables but you can declare them before assigning a value... Loops are great - they do things until a specific criteria is met....then I exit or break out of them. Functions are code that do specific tasks (or series of tasks) & can be called upon at any given time during a script. An array is like a....hotel with many different rooms - each room being a different value. I get GET and POST...and know how to use them between pages. Sessions can be used to pass data between pages - they help to keep track of things.... Cookies are like little signatures from your script that you can give to a users browser for any number of reasons. I guess you could say I'm starting to get it. It's only been 4 months. That being said can someone give me a brief and yet simple summary of what a PHP Class is... Hi guys Sorry i keep asking noob questions today... I'm working on something that has a user facing image upload facility. So i'm slowly working through a class to make this as secure as possible. One of the tips online is to use the method "is_uploaded_file ( )". According to php.net - "Returns TRUE if the file named by filename was uploaded via HTTP POST. This is useful to help ensure that a malicious user hasn't tried to trick the script into working on files upon which it should not be working--for instance, /etc/passwd. " I'm not one to just use things without understanding why. So how exactly could someone get a script to work on an internal file via a browse/upload facility? Hi.
I haven't done a lot of OOP. Hardly any really. I've had a go at writing a very small class that outputs a greeting depending on what time of day it is. What do the OOP experts here make of it? What do you like, what do you hate? Is there anything I could do to make it more useful?
Here is the code;
class Greeting { // the __construct didn't do what I originally wanted. Denfine the hour outside the method (I don't know why this is a good/bad idea) /* public function __construct() { $hour_of_day = date('G'); } */ public function callGreetingPhrase() { return $this->getGreetingPhrase(); } // the setter doesn't seem to have a purpose here. I tried using it so that I could pass in a value of my choosing (for testing purposes) can't get it to work though /* public function setGreetingPhrase($value) { $this->hour_of_day = $value; } */ private function getGreetingPhrase() { $hour_of_day = date('G'); if($hour_of_day < 12 ) { // if it's before 12pm $greeting_phrase = "good morning"; } elseif($hour_of_day >= 12 && $hour_of_day < 18 ) { // if it's after 12pm but before 6pm $greeting_phrase = "good afternoon"; } else { // what is left over - after 6pm until midnight $greeting_phrase = "good evening"; } return $greeting_phrase; } } $greeting = new Greeting; echo $greeting->callGreetingPhrase();It annoyed me that I could 't figure out how to use the __constructor here to store the hour. But should that have bothered me? Can someone maybe explain a bit about the setter that I tried to use setGreetingPhrase. I only put it in because I've seen other Classes with one. Could I use a setter method here for anything useful? Any feedback appreciated! I need some help understanding the below syntax (the ? and the colon are throwing me) isset($_POST['cardType']) ? $_POST['cardType'] : ''; Thanks for any help on this .. Frank Hi.
I've been trying to understand the concept of password_hash but so far it has eluded me!
registration
<?php if(isset($_POST['submit'])){ $name = $_POST['name']; $email = $_POST['email']; $password = $_POST['password']; //$pass_hash = PassHash::hash($_POST['password']); $hash = password_hash($password, PASSWORD_BCRYPT); $stmt = $pdo->prepare("INSERT INTO hash_test(name, email, password) VALUES(:name, :email, :password)"); $stmt->execute(array( ':name' => $name, ':email' => $email, ':password' => $hash )); if ($stmt->rowCount() ==1){ echo "Registration Successful"; }else{ echo "There was a problem taking your request"; } } ?>The registration is working fine and all fields are inserted. The problem is when loggin in, its giving me an error : unknown variable which is the $hash. The verify parameter is thus: password_verify($password, $hash) I believe the $password is the users password for login, now how/when/where do assign a value to $hash? since in my db i have email(username) password. Do i need to store the hash separately on the db? Can someone please enlighten me more my login code <?php if(isset($_POST['login'])){ $password = $_POST['password']; $stmt = $pdo->prepare("SELECT email, password FROM hash_test WHERE email=:email AND password=:password"); $stmt->execute(array( ':email' => $_POST['email'], ':password' =>$password )); //if ($stmt->rowCount() ==1){ if (password_verify($password, $hash)) { /* Valid */ echo "Right"; } else { /* Invalid */ echo "wrong"; } //} } ?>THANKS |