2022-10-18

Oct 19 In-Class Exercise.

Please post your solutions to the Oct 19 In-Class Exercise to this thread.
Best,
Chris
Please post your solutions to the Oct 19 In-Class Exercise to this thread. Best, Chris
2022-10-19

-- Oct 19 In-Class Exercise
 StringHolder.php
 
 <?php
 namespace some_company\some_project;
 class StringHolder{ 
	public $my_string;
	function __construct($a_string){
		$this->my_string = $a_string;
	}
 }
 main.php
 <?php
 use some_company\some_project\StringHolder;
 require("StringHolder.php");
 $string_holder = new StringHolder("hi there");
 echo $string_holder->my_string . "\n";
 PS C:\Users\markm\desktop\cs174\1019> php main.php
 hi there
 PS C:\Users\markm\desktop\cs174\1019>
(Edited: 2022-10-19)
StringHolder.php <?php namespace some_company\some_project; class StringHolder{ public $my_string; function __construct($a_string){ $this->my_string = $a_string; } } main.php <?php use some_company\some_project\StringHolder; require("StringHolder.php"); $string_holder = new StringHolder("hi there"); echo $string_holder->my_string . "\n"; PS C:\Users\markm\desktop\cs174\1019> php main.php hi there PS C:\Users\markm\desktop\cs174\1019>

-- Oct 19 In-Class Exercise
<?php
    class StringHolder {
        public $my_string = "";
        function _construct($a_string) {
            $my_string = $a_string;
        }
    }
?>
<?php
    //OTHER FILE
    require_once("index.php");
    use StringHolder ;
    $string_holder = new StringHolder("hi there");
    echo $string_holder->my_string ."\n";   
?>
<?php class StringHolder { public $my_string = ""; function _construct($a_string) { $my_string = $a_string; } } ?> <?php //OTHER FILE require_once("index.php"); use StringHolder ; $string_holder = new StringHolder("hi there"); echo $string_holder->my_string ."\n"; ?>

-- Oct 19 In-Class Exercise
// StringHolder.php
(Edited: 2022-10-19)
<nowiki>// StringHolder.php <?php namespace some_company\some_project; class StringHolder { public $my_string; function __construct($a_string) { $this->my_string = $a_string; } } // index.php <?php use some_company\some_project\StringHolder ; require_once("index.php"); $string_holder = new StringHolder("hi there"); echo $string_holder->my_string."\n"; // test run (base) JaimeAdele@MacBook-Pro-2 namespace % php other.php hi there</nowiki>

-- Oct 19 In-Class Exercise
<nowiki> <?php namespace some_company\some_project; class StringHolder { public $my_string; function __construct($a_string) { $this->my_string = $a_string; } } <?php use some_company\some_project\StringHolder; require_once ('test.php'); $string_holder = new StringHolder("hi there"); echo $string_holder->my_string ."\n"; </nowiki>

-- Oct 19 In-Class Exercise
namespace companyX\test_project;
class StringHolder{
    public $my_string;
    function __construct($a_string){
        $this->my_string=$a_string;
    }
} //second file <?php require_once('StringHolder.php');
use companyX\test_project as C;
$string_holder = new C\StringHolder("hi there"); echo $string_holder->my_string ."\n";
//Output siddhitajoshi@Siddhitas-MacBook-Pro test_project % php test.php hi there
(Edited: 2022-10-19)
namespace companyX\test_project; class StringHolder{ public $my_string; function __construct($a_string){ $this->my_string=$a_string; } } //second file <?php require_once('StringHolder.php'); use companyX\test_project as C; $string_holder = new C\StringHolder("hi there"); echo $string_holder->my_string ."\n"; //Output siddhitajoshi@Siddhitas-MacBook-Pro test_project % php test.php hi there

-- Oct 19 In-Class Exercise
//StringHolder.php
<nowiki> //StringHolder.php <?php namespace some_company\some_project; class StringHolder { public $my_string; function __construct($a_string){ $this->my_string = $a_string; } } //other.php <?php use some_company\some_project\StringHolder; require("StringHolder.php"); $string_holder = new StringHolder("hi there"); echo $string_holder->my_string . "\n"; </nowiki>

-- Oct 19 In-Class Exercise
<?php namespace some_company\some_project;
class Stringholder{
    public $my_string;
    function __construct($str){
        $this->my_string = $str;
    }
}
// Tester.php <?php
  use some_company\some_project\Stringholder;
  require_once("Stringholder.php");
  $string_holder = new Stringholder("hi there");
  echo $string_holder->my_string . "\n";
?>
sabrinaly@Sabrinas-MacBook-Pro Practice5 (main) $ php tester.php hi there
<?php namespace some_company\some_project; class Stringholder{ public $my_string; function __construct($str){ $this->my_string = $str; } } // Tester.php <?php use some_company\some_project\Stringholder; require_once("Stringholder.php"); $string_holder = new Stringholder("hi there"); echo $string_holder->my_string . "\n"; ?> sabrinaly@Sabrinas-MacBook-Pro Practice5 (main) $ php tester.php hi there

-- Oct 19 In-Class Exercise
StringHolder.php
<?php namespace some_company\some_project;
class StringHolder{
    private $my_string;
    function __construct($a_string){
        my_string = $a_string;
    }
} ?>
class.php
<?php use some_company\some_project\StringHolder; require_once("stringHolder.php");
$string_holder = new StringHolder("hi there"); echo $string_holder->my_string ."\n"; ?>
(Edited: 2022-10-19)
StringHolder.php <?php namespace some_company\some_project; class StringHolder{ private $my_string; function __construct($a_string){ my_string = $a_string; } } ?> class.php <?php use some_company\some_project\StringHolder; require_once("stringHolder.php"); $string_holder = new StringHolder("hi there"); echo $string_holder->my_string ."\n"; ?>

-- Oct 19 In-Class Exercise
file a.php <?php namespace company\assignment;
class StringHolder{
  public $my_string;
  function __construct($a_string){
    $this->$my_string = $a_string;
  }
}
file b.php <?php use company\assignment\StringHolder;
require_once("a.php");
$string_holder = new StringHolder("I'm a string!"); echo $string_holder->$my_string."\n";
//test run I'm a string!
file a.php <?php namespace company\assignment; class StringHolder{ public $my_string; function __construct($a_string){ $this->$my_string = $a_string; } } file b.php <?php use company\assignment\StringHolder; require_once("a.php"); $string_holder = new StringHolder("I'm a string!"); echo $string_holder->$my_string."\n"; //test run I'm a string!
[ Next ]
X