Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'string'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 3 results

  1. I've been banging on the following error for awhile and I cannot tell what is wrong, please help: Catchable fatal error: Argument 2 passed to ShapeFactory::Create() must be an array, string given, called in /home/content/14/11625314/html/AdvPHPwOOP/factory.php on line 22 and defined in /home/content/14/11625314/html/AdvPHPwOOP/ShapeFactory.php on line 11 I'm using PHP 5.3 thru goDaddy Here's the code: <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Factory</title> <link rel="stylesheet" href="style.css"> </head> <body> <?php # Script 7.4 - factory.php // This page uses the ShapeFactory class (Script 7.2). // Load the class definitions: require('ShapeFactory.php'); require('Shape.php'); require('Triangle.php'); require('Rectangle.php'); // Minimal validation: if (isset($_GET['shape'], $_GET['dimensions'])) { // Create the new object: $obj=ShapeFactory::Create($_GET['shape'],$_GET['dimensions']); // Print a little introduction: echo "<h2>Creating a {$_GET['shape']}...</h2>"; // Print the area: echo '<p>The area is ' . $obj->getArea() . '</p>'; // Print the perimeter: echo '<p>The perimeter is ' . $obj->getPerimeter() . '</p>'; } else { echo '<p class="error">Please provide a shape type and size.</p>'; } // Delete the object: unset($obj); ?> </body> </html> **************** <?php # Script 7.3 - ShapeFactory.php // This page defines a ShapeFactory class which uses the Factory pattern. /* The ShapeFactory class. * The class contains no attributes. * The class contains one method: Create(). */ abstract class ShapeFactory { // Static method that creates objects: static function Create($type, array $sizes) { // Determine the object type based upon the parameters received. switch ($type) { case 'rectangle': return new Rectangle($sizes[0], $sizes[1]); break; case 'triangle': return new Triangle($sizes[0], $sizes[1], $sizes[2]); break; } // End of switch. } // End of Create() method. } // End of ShapeFactory class.
  2. $array2=array('name'=>array('laith','raad','hamid'),'age'=>array(20,30,40),'gender'=>'male'); print_r($array2); echo $c2=count($array2); foreach($array2 as $k=>$v) { if($array2 < $c2) { foreach($array2 as $k=>$v) { echo $k . ' ' . $v . "<br/>"; } } echo $k . ' ' . $v . "<br/>"; } // i have a problem //NOTICE: array to string conversion on the last line // i need solution ?????????????????????????????????
  3. I've read through the book, and now I'm working through it bit by bit; I am so hung up on this one subject that I need to ask for some clarification. In script 2.7 I'm working through arrays, and how to indicate strings, etc. On p. 64 the box on the right says that multi-dimensional arrays can also come from an html form- and since this is what I want to figure out how to create, I thought I would try to write the correct syntax for this to understand it thoroughly. Here's the code- a simple form that has check boxes and then sub check boxes; I realize this might be a bit more complex than the example but it indicates best what I want to try to work through. <?php $letts = array( $_POST['letters'], ); if ($_SERVER['REQUEST_METHOD'] == 'POST') { foreach($letts as $title => $list) { echo "<h3>$title</h2><ul>\n"; foreach($title as $k => $v) { echo "<li>$k - $v</li>\n"; } } echo '</ul>'; } ?> <!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"> body, ul, li { list-style-type: none; } </style> </head> <body> <form action="page1.php" method="post"> <fieldset> <legend>My Form</legend> <fieldset> <legend>Letters and Numbers: 1</legend> <ul> <li> <input type="checkbox" name="letters[]" value="Alpha" /> Alpha <ul> <li><input type="checkbox" name="numbers[]" value="One" /> One</li> <li><input type="checkbox" name="numbers[]" value="Two" /> Two</li> <li><input type="checkbox" name="numbers[]" value="Three" /> Three</li> <li><input type="checkbox" name="numbers[]" value="Four" /> Four</li> </ul> </li> </fieldset> <fieldset> <legend> Two:</legend> <ul> <li> <input type="checkbox" name="letters[]" value="Beta" /> Beta <ul> <li><input type="checkbox" name="numbers[]" value="One" /> One</li> <li><input type="checkbox" name="numbers[]" value="Two" /> Two</li> <li><input type="checkbox" name="numbers[]" value="Three" /> Three</li> <li><input type="checkbox" name="numbers[]" value="Four" /> Four</li> </ul> </li> </ul> </fieldset> <fieldset> <legend> Teh Three:</legend> <ul> <li><input type="checkbox" name="letters[]" value="Charlie" /> Charlie <ul> <li><input type="checkbox" name="numbers[]" value="One" /> One</li> <li><input type="checkbox" name="numbers[]" value="Two" /> Two</li> <li><input type="checkbox" name="numbers[]" value="Three" /> Three</li> <li><input type="checkbox" name="numbers[]" value="Four" /> Four</li> </ul> </li> </ul> </fieldset> <fieldset> <legend> Four!</legend> <ul> <li><input type="checkbox" name="letters[]" value="Delta" /> Delta <ul> <li><input type="checkbox" name="numbers[]" value="One" /> One</li> <li><input type="checkbox" name="numbers[]" value="Two" /> Two</li> <li><input type="checkbox" name="numbers[]" value="Three" /> Three</li> <li><input type="checkbox" name="numbers[]" value="Four" /> Four</li> </ul> </li> </ul> </fieldset> <br /> <input type="submit" value="submit" name="Submit!!" /> </fieldset> </form> </body> </html> I should say, this is the latest version; previous versions (I've tried a lot of different things but realize that I'm just altering things without understanding what is really going wrong) have returned different errors such as illegal string offset. This one returns the warning that you gave a tip for on page 61- invalid argument foreach. So I'm trying to use a foreach loop on a variable that is not an array- but I suppose I don't understand why it is not an array- is it because the letters[] and numbers[] are not given a relation? should they all have the same name? I thought it was because in some instances I checked only one option- so I tried going through each list and checking multiple in each one. Then I realized that this wouldn't work anyway, because I don't want to create any sort of form where multiple check box values are required instead of optional. If you had any insight on this I would be grateful. Thanks!
×
×
  • Create New...