1

I've a object called 'Booking' with about 13 properties however while attempting to run the following code.

$bookingDateTime = date('Y-m-d H:i:s');
$booking = new Booking(....,$bookingDateTime);
echo "START OF TEST <br>";
echo "$bookingDateTime <br>";
echo "$booking->bookingDateTime <br>";
echo "END OF TEST <br>";

It always echoes without the second DateTime.

START OF TEST 
2018-08-07 04:38:27 

END OF TEST

I am unsure what am i missing or is DateTime objects not allowed in PHP Objects?

Within Booking Object is the following

Class Booking{
    public $bookingDateTime;
    function __construct($bookingDateTime){
        $this->$bookingDateTime = $bookingDateTime;
    }
}
14
  • try to write it into variable Commented Aug 7, 2018 at 4:52
  • What are you doing with the $bookingDateTime constructor argument in the constructor? Commented Aug 7, 2018 at 4:52
  • 1
    You'll need to show the relevant parts of your booking class if you want an exact answer, we can't guess what it looks like. Commented Aug 7, 2018 at 4:59
  • 1
    This is why you should always provide a Minimal, Complete, and Verifiable example Commented Aug 7, 2018 at 5:06
  • 2
    It's an easy mistake to make, we all have done so at one point. Though let this show why it is important that you share all the relevant parts of the code, there is no way we cold have known that without you posting your code :) Commented Aug 7, 2018 at 5:08

2 Answers 2

1

Thanks to @Phil and @Qirel in the comments for your help and advice, and everyone else.

It was a typo on $this->$bookingDateTime where the actualy problem was the extra $ in the object Booking.

$this->bookingDateTime = $bookingDateTime;

And read up on Minimal, Complete, and Verifiable example for future questions..

Sign up to request clarification or add additional context in comments.

1 Comment

This really didn't need an answer
0

you should write that

   Class Booking{
       public $bookingDateTime;
        function __construct($bookingDateTime){
          $this->bookingDateTime = $bookingDateTime;
       }
   }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.